Excel Macro Assistance
Solved/Closed
dhunter
Posts
6
Registration date
Wednesday December 15, 2010
Status
Member
Last seen
January 2, 2011
-
Dec 29, 2010 at 11:01 PM
Helper - Jan 2, 2011 at 06:54 PM
Helper - Jan 2, 2011 at 06:54 PM
Related:
- Excel Macro Assistance
- Spell number in excel without macro - Guide
- Excel mod apk for pc - Download - Spreadsheets
- Excel marksheet - Guide
- Kernel for excel - Download - Backup and recovery
- Macros in excel download free - Download - Spreadsheets
4 responses
This code assumes there are no blank spaces in column D where you are using the vlookup reference. So, when it is using the Do Loop it will fill the formula in column H until there is no more data in column D. If the length of the data in the QA sheet needs to match the length of the Previous Week sheet, then the Do Loop must be changed to reference the Previous Week sheet or the code will not run long enough to capture the data from the Previous Week sheet.
Hope this helps!
Set q = Sheets("QA")
Dim i
i = 2
q.Activate
Columns("H:H").Select
Selection.Insert Shift:=xlToRight, CopyOrigin:=xlFormatFromLeftOrAbove
Range("H1") = "Tester"
Do Until q.Range("D" & i) = ""
q.Range("H" & i) = "=vlookup(D" & i & ",'Previous Week'!D:G,4,false)"
i = i + 1
Loop
Columns("H:H").Select
Selection.Copy
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Application.CutCopyMode = False
Range("H1").Select
Hope this helps!
Set q = Sheets("QA")
Dim i
i = 2
q.Activate
Columns("H:H").Select
Selection.Insert Shift:=xlToRight, CopyOrigin:=xlFormatFromLeftOrAbove
Range("H1") = "Tester"
Do Until q.Range("D" & i) = ""
q.Range("H" & i) = "=vlookup(D" & i & ",'Previous Week'!D:G,4,false)"
i = i + 1
Loop
Columns("H:H").Select
Selection.Copy
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Application.CutCopyMode = False
Range("H1").Select
dhunter
Posts
6
Registration date
Wednesday December 15, 2010
Status
Member
Last seen
January 2, 2011
Dec 30, 2010 at 08:14 AM
Dec 30, 2010 at 08:14 AM
Ill have to try this out. The data on the QA sheet will always have more than the previous week.
dhunter
Posts
6
Registration date
Wednesday December 15, 2010
Status
Member
Last seen
January 2, 2011
Jan 2, 2011 at 02:37 AM
Jan 2, 2011 at 02:37 AM
Thanks Helper,
This code works great. I'm using the same format you have here and attempting to TRIM and Concatenate columns.
the TRIM format is working but not the concatenate..
q.Range("D" & i) = "Concatenate(C" & i & "," ", B" & i & ")
can you help?
This code works great. I'm using the same format you have here and attempting to TRIM and Concatenate columns.
the TRIM format is working but not the concatenate..
q.Range("D" & i) = "Concatenate(C" & i & "," ", B" & i & ")
can you help?
dhunter
Posts
6
Registration date
Wednesday December 15, 2010
Status
Member
Last seen
January 2, 2011
Jan 2, 2011 at 12:27 PM
Jan 2, 2011 at 12:27 PM
that didnt work for me. Here is the code that I am using for the process.
Sub Student_Name_Test()
'
' Student_Name_Test Macro
'
'
Set q = Sheets("Tester")
Dim i
i = 2
q.Activate
Columns("D:E").Select
Selection.Insert Shift:=xlToRight, CopyOrigin:=xlFormatFromLeftOrAbove
Range("D1") = "Last Name TRIM"
Range("E1") = "First Name TRIM"
Do Until q.Range("J" & i) = ""
q.Range("D" & i) = "=TRIM(B" & i & ")"
q.Range("E" & i) = "=TRIM(C" & i & ")"
i = i + 1
Loop
Columns("D:E").Select
Selection.Copy
Columns("B:B").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Application.CutCopyMode = False
Columns("D:E").Select
Application.CutCopyMode = False
Selection.Delete Shift:=xlToLeft
Columns("D:D").Select
Selection.Insert Shift:=xlToRight, CopyOrigin:=xlFormatFromLeftOrAbove
Range("D1") = "First Last Name"
Do Until q.Range("B" & i) = ""
q.Range("D" & i) = "Concatenate(C" & i & ", B" & i & ")"
i = i + 1
Loop
Columns("D:D").Select
End Sub
what am I missing here?
Sub Student_Name_Test()
'
' Student_Name_Test Macro
'
'
Set q = Sheets("Tester")
Dim i
i = 2
q.Activate
Columns("D:E").Select
Selection.Insert Shift:=xlToRight, CopyOrigin:=xlFormatFromLeftOrAbove
Range("D1") = "Last Name TRIM"
Range("E1") = "First Name TRIM"
Do Until q.Range("J" & i) = ""
q.Range("D" & i) = "=TRIM(B" & i & ")"
q.Range("E" & i) = "=TRIM(C" & i & ")"
i = i + 1
Loop
Columns("D:E").Select
Selection.Copy
Columns("B:B").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Application.CutCopyMode = False
Columns("D:E").Select
Application.CutCopyMode = False
Selection.Delete Shift:=xlToLeft
Columns("D:D").Select
Selection.Insert Shift:=xlToRight, CopyOrigin:=xlFormatFromLeftOrAbove
Range("D1") = "First Last Name"
Do Until q.Range("B" & i) = ""
q.Range("D" & i) = "Concatenate(C" & i & ", B" & i & ")"
i = i + 1
Loop
Columns("D:D").Select
End Sub
what am I missing here?
Two things....1) when using the variable "i" multiple times throughout the code, you need to re-declare the variable before the next Do Loop. So, before the next Do Loop in which you are referencing column B, make i equal to 2. 2) The Concatenate formula needs to be changed to the way I have it below. It is missing an = at the beginning and the quote marks are not in the correct places.
i = 2
Do Until q.Range("B" & i) = ""
q.Range("D" & i) = "=Concatenate(C" & i & ", B" & i & ")"
i = i + 1
Loop
Columns("D:D").Select
i = 2
Do Until q.Range("B" & i) = ""
q.Range("D" & i) = "=Concatenate(C" & i & ", B" & i & ")"
i = i + 1
Loop
Columns("D:D").Select
dhunter
Posts
6
Registration date
Wednesday December 15, 2010
Status
Member
Last seen
January 2, 2011
Jan 2, 2011 at 05:11 PM
Jan 2, 2011 at 05:11 PM
Great, that concatenate worked, but excel isnt putting a space between the merged cells.