Macro Help-Autofill Issue?

johnnydop

New Member
Joined
Aug 13, 2009
Messages
10
I have two columns, one with text (col a) and one with a date stored as text (col b). The code below creates a new column (col c) where it places the text from col a and the "date" from col b together seperated by two dashes, "--".

The problem i have is the data set i'm using will not always be the same number of rows. As you can see below, the following line of code (Range("B6:B32").Select) uses a row range of B6-B32 because that was the amount of rows in the file when i recorded the macro.
i.e. If the number or rows is less then 32, the code applies to rows 32 and and beyond, and if the number of rows is more then 32, it will miss anything after row 32.

How can i update the code so it will apply that code to what ever number of consecutive rows exist, or the equivalent of a "control+shift+down"?

Sub formatdate()
'
' formatdate Macro
' Macro recorded 8/13/2009 by
'
'
Worksheets("Position Rec").Select
Range("B6").Select
ActiveCell.FormulaR1C1 = _
"=RC[4]&""--""&MID(RC[22],5,2)&""/""&RIGHT(RC[22],2)&""/""&LEFT(RC[22],4)"
Range("B6").Select
Selection.AutoFill Destination:=Range("B6:B32")
Range("B6:B32").Select
Selection.Copy
Range("F6").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Columns("B:B").Select
Application.CutCopyMode = False
Selection.ClearContents
Range("B6").Select
MsgBox "Done!"
End Sub

Thanks!
 

Excel Facts

Workdays for a market open Mon, Wed, Friday?
Yes! Use "0101011" for the weekend argument in NETWORKDAYS.INTL or WORKDAY.INTL. The 7 digits start on Monday. 1 means it is a weekend.
Something like this perhaps.
Code:
    With Worksheets("Position Rec")
        LastRow = .Range("A" & Rows.Count).End(xlUp).Row
        With .Range("B6:B" & LastRow)
            .FormulaR1C1 = "=RC[4]&""--""&MID(RC[22],5,2)&""/""&RIGHT(RC[22],2)&""/""&LEFT(RC[22],4)"
            .Copy
            .Offset(, 4).PasteSpecial Paste:=xlPasteValues
            .EntireColumn.ClearContents
        End With
    End With
 
    MsgBox "Done!"
 
Upvote 0
So this code will replace all of the code in my post?


Something like this perhaps.
Code:
    With Worksheets("Position Rec")
        LastRow = .Range("A" & Rows.Count).End(xlUp).Row
        With .Range("B6:B" & LastRow)
            .FormulaR1C1 = "=RC[4]&""--""&MID(RC[22],5,2)&""/""&RIGHT(RC[22],2)&""/""&LEFT(RC[22],4)"
            .Copy
            .Offset(, 4).PasteSpecial Paste:=xlPasteValues
            .EntireColumn.ClearContents
        End With
    End With
 
    MsgBox "Done!"
 
Upvote 0

Forum statistics

Threads
1,214,653
Messages
6,120,750
Members
448,989
Latest member
mariah3

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top