![]() |
Clean up code.
I am a basic excel user and here is my macro. I am trying to set whatever
sheet is open as the active sheet, pick a cell from that sheet value equal to LL-CP-0100 and assign a variable to the number part ie 0100. My such variable is "j" below. I also set a variable i which should equal j+1. Then i want to use i and j in the code as shown below. Can someone help clean the code. ' Macro recorded 9/30/2004 by Husky User ' Sub Atester() Dim sStr As String Dim pos As Long Dim i As Long Dim j As Long Windows"current sheet".Activate Range("J2").Select sStr = "J2" pos = InStrRev(sStr, "-") i = Mid(sStr, pos + 1) + 1 j = i - 1 MsgBox i MsgBox j Windows("LL-CP-j.xls").Activate Range("F3:H3").Select Application.CutCopyMode = False Selection.Copy Windows("Completions LL Register 2004-09-030.xls").Activate Range("F"i"").Select Selection.PasteSpecial Paste:=xlValues, Operation:=xlNone, SkipBlanks:= _ False, Transpose:=False End Sub |
Clean up code.
Tim,
It looks like the line: Range("F"i"").Select should be something like: Range("F" & i).Select This will set it to F3 or F81 or whatever the value of I is so you can do your paste. -----Original Message----- I am a basic excel user and here is my macro. I am trying to set whatever sheet is open as the active sheet, pick a cell from that sheet value equal to LL-CP-0100 and assign a variable to the number part ie 0100. My such variable is "j" below. I also set a variable i which should equal j+1. Then i want to use i and j in the code as shown below. Can someone help clean the code. ' Macro recorded 9/30/2004 by Husky User ' Sub Atester() Dim sStr As String Dim pos As Long Dim i As Long Dim j As Long Windows"current sheet".Activate Range("J2").Select sStr = "J2" pos = InStrRev(sStr, "-") i = Mid(sStr, pos + 1) + 1 j = i - 1 MsgBox i MsgBox j Windows("LL-CP-j.xls").Activate Range("F3:H3").Select Application.CutCopyMode = False Selection.Copy Windows("Completions LL Register 2004-09- 030.xls").Activate Range("F"i"").Select Selection.PasteSpecial Paste:=xlValues, Operation:=xlNone, SkipBlanks:= _ False, Transpose:=False End Sub . |
Ignore this post
sorry wrong post |
All times are GMT +1. The time now is 12:09 PM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com