Need help going down a line in Excel VBA

Solved/Closed
mndude Posts 2 Registration date Friday 15 January 2016 Status Member Last seen 15 January 2016 - 15 Jan 2016 à 18:40
 Blocked Profile - 15 Jan 2016 à 19:19
Hello good folks,

Please, I'm trying to write a simple Excel macro that will basically click on hyperlinks within the cells, but I don't know how to have it go down to the next line automatically. Here is what I currently have:

"Selection.Hyperlinks(1).Follow NewWindow:=False, AddHistory:=True
Range("E4").Select
Application.Wait Now + TimeValue("00:00:20")
Selection.Hyperlinks(1).Follow NewWindow:=False, AddHistory:=True
Range("E5").Select
Application.Wait Now + TimeValue("00:00:20")
Selection.Hyperlinks(1).Follow NewWindow:=False, AddHistory:=True
Range("E6").Select
Application.Wait Now + TimeValue("00:00:20")
Selection.Hyperlinks(1).Follow NewWindow:=False, AddHistory:=True
Range("E7").Select
Selection.Hyperlinks(1).Follow NewWindow:=False, AddHistory:=True
Range("E8").Select
Selection.Hyperlinks(1).Follow NewWindow:=False, AddHistory:=True"

As there'll be thousands of lines to go down to, I would like to have it just go to the next line without having to write thousands of lines of code like this. How should I type this? Someone mentioned using the For Loop command, but I am so new to this that I would have no idea how to enter that. Please how should I write this?

Thank you in advance for your help with this.


Related:

1 response

Blocked Profile
15 Jan 2016 à 19:19
A "FOR" loop will do this.

So set a variable to the number of lines, as in:


dim x, t
dim countx, rowletter
dim theactivesheet
rowletter="E"
x=theactivesheet.numberofrows.count
for t = 1 to x
countx=rowletter+x
Range(countx).Select
Application.Wait Now + TimeValue("00:00:20")
Selection.Hyperlinks(1).Follow NewWindow:=False, AddHistory:=True
next


So, there ya go. I must tell ya, I am not here to troubleshoot the above code. The above code is meant as an example of what you are attempting to cut and paste together, as in SCRIPT KIDDIE!

I can only hope that you have learned something, and will continue to explore the world of programming. Once again, this code will not run as published (well not on VBSCRIPT)!

Have FUN!


I have said it once, I will say it again. IT!