Hi Jeff,
I think you're right.
When I pressed Ctrl + End, it points me to the correct end (where the last data is, say it's row 50) in the excel workbook that I used when creating this code. However when I tried it with the other ones, it didn't point me to where the last data is. It stopped at row 50 regardless whether there's any data there or not. Why is that? Is there any way I can correct this?
Because of this, whenever I imported the sheet to access, access keeps on generating 50 rows or records regardless whether there are only 20 rows of data, etc.
Here's the full code that I have now. I have expanded your code (as you can see)
Thanks!
Sub Account_String()
'
' Account_String Macro
'
' Keyboard Shortcut: Ctrl+g
'
Dim LR As Long
LR = Range("A" & Rows.Count).End(xlUp).Row
Columns("C:C").Insert Shift:=xlToRight, CopyOrigin:=xlFormatFromLeftOrAbove
Range("C1").FormulaR1C1 = "Full Name"
With Range("C2:C" & LR)
.FormulaR1C1 = "=CONCATENATE(RC[-1],"" "",RC[-2])"
.Value = .Value
End With
LR = Range("A" & Rows.Count).End(xlUp).Row
Columns("K:K").Insert Shift:=xlToRight, CopyOrigin:=xlFormatFromLeftOrAbove
Range("K1").FormulaR1C1 = "Department"
With Range("K2:K" & LR)
.FormulaR1C1 = "=LEFT(RC[-1],4)"
.Value = .Value
End With
Columns("W:W").EntireColumn.AutoFit
LR = Range("A" & Rows.Count).End(xlUp).Row
Columns("X:X").Insert Shift:=xlToRight, CopyOrigin:=xlFormatFromLeftOrAbove
Range("X1").FormulaR1C1 = "Region"
With Range("X2:X" & LR)
.FormulaR1C1 = "=LEFT(RC[-1],3)"
.Value = .Value
End With
LR = Range("A" & Rows.Count).End(xlUp).Row
Columns("Z:Z").Insert Shift:=xlToRight, CopyOrigin:=xlFormatFromLeftOrAbove
Range("Z1").FormulaR1C1 = "Unit Center"
With Range("Z2:Z" & LR)
.FormulaR1C1 = "=LEFT(RC[-1],4)"
.Value = .Value
End With
LR = Range("A" & Rows.Count).End(xlUp).Row
Range("AB1").FormulaR1C1 = "Account String"
With Range("AB2:AB" & LR)
.FormulaR1C1 = "=CONCATENATE(RC[-8],""-"",""000"",""-"",RC[-4],""-"",RC[-17],""-"",RC[-2])"
.Value = .Value
End With
Columns("AB:AB").EntireColumn.AutoFit
Selection.Copy
Range("AB1").Select
Selection.PasteSpecial Paste:=xlPasteFormats, Operation:=xlNone, _
SkipBlanks:=False, Transpose:=False
Application.CutCopyMode = False
Columns("AB:AB").Select
Selection.Copy
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Application.CutCopyMode = False
ActiveCell.FormulaR1C1 = "Account String"
Columns("C:C").Select
Selection.Copy
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Application.CutCopyMode = False
Range("A:B,D:D,F:AA").Select
Range("F1").Activate
Selection.Delete Shift:=xlToLeft
Columns("A:A").Select
Selection.Insert Shift:=xlToRight, CopyOrigin:=xlFormatFromLeftOrAbove
Columns("C:C").Select
Selection.Cut
Columns("A:A").Select
ActiveSheet.Paste
Columns("C:C").Select
Selection.Delete Shift:=xlToLeft
Columns("A:C").Select
Columns("A:C").EntireColumn.AutoFit
Range("A1").Select
Columns("C:C").Select
Selection.Insert Shift:=xlToRight, CopyOrigin:=xlFormatFromLeftOrAbove
Selection.Insert Shift:=xlToRight, CopyOrigin:=xlFormatFromLeftOrAbove
LR = Range("A" & Rows.Count).End(xlUp).Row
Range("C1").FormulaR1C1 = "Period"
With Range("C2:C" & LR)
.FormulaR1C1 = "=TODAY()"
.Value = .Value
End With
Range("C2:C9219").Select
Selection.NumberFormat = "[$-409]mmm-yy;@"
LR = Range("A" & Rows.Count).End(xlUp).Row
Range("D1").FormulaR1C1 = "Period Date"
With Range("D2:D" & LR)
.FormulaR1C1 = "=TEXT(TODAY()-DAY(TODAY())+1,""m/d/yyyy"")"
.Value = .Value
End With
Range("A1").Select
End Sub
Bookmarks