VBA Range("A" & Rows.count).End(xlUp).Offset(1, 0)

geloader0

Board Regular
Joined
Dec 21, 2022
Messages
52
Office Version
  1. 2016
Platform
  1. Windows
Hi, Good day. I have data with 55 rows. In this code
Excel Formula:
Range("A" & Rows.count).End(xlUp).Offset(1, 0)

It starts paste the value in the last available row so it starts from Range("A56"). But I want to paste the value starting from A3 to A55. Any help? Thanks
 

Excel Facts

Copy formula down without changing references
If you have =SUM(F2:F49) in F50; type Alt+' in F51 to copy =SUM(F2:F49) to F51, leaving the formula in edit mode. Change SUM to COUNT.
Use Range("A3"), it will start from A3 instead of A56.
 
Upvote 0
Use Range("A3"), it will start from A3 instead of A56.
Hi. This will result to duplicate value. Anyway, I'm using DO while loop..

This is the code.. Thanks to

shinigamilight

Excel Formula:
        Dim d As Date
        d = DateValue("31-dec-22")
        Dim LastDate As Date
        Dim StartDate As Date

        Do
         k = k + 7
         LastDate = DateAdd("d", k, d)
         StartDate = LastDate - 6
         Range("A" & Rows.Count).End(xlUp).Offset(1, 0) = StartDate & " - " & LastDate
        Loop While LastDate <= CDate("1-jan-24")
 
Upvote 0
You can choose to clear your old data adding this line just before the Do :
VBA Code:
Range("A3:A" & Range("A" & Rows.Count).End(xlUp).Row).ClearContents
or add a row counter to your macro like this and overwrite old data:
Code:
Option Explicit
Sub test()
    Dim d As Date
    d = DateValue("31-dic-22")
    Dim LastDate As Date
    Dim StartDate As Date
    Dim k As Long, rw As Long                '<- added
    rw = 3                                        '<- added
    Do
        k = k + 7
        LastDate = DateAdd("d", k, d)
        StartDate = LastDate - 6
        Range("A" & rw) = StartDate & " - " & LastDate '<- changed
        rw = rw + 1                               '<- added
    Loop While LastDate <= CDate("1-gen-24")
End Sub
 
Upvote 0
Solution
or add a row counter to your macro like this and overwrite old data:
Code:
Option Explicit
Sub test()
    Dim d As Date
    d = DateValue("31-dic-22")
    Dim LastDate As Date
    Dim StartDate As Date
    Dim k As Long, rw As Long                '<- added
    rw = 3                                        '<- added
    Do
        k = k + 7
        LastDate = DateAdd("d", k, d)
        StartDate = LastDate - 6
        Range("A" & rw) = StartDate & " - " & LastDate '<- changed
        rw = rw + 1                               '<- added
    Loop While LastDate <= CDate("1-gen-24")
End Sub

This one much better. Thank you so much
 
Upvote 0
Thanks for the positive feedback(y), glad having been of some help.
 
Upvote 1
Thanks for the positive feedback(y), glad having been of some help.

Hi, Good day @rollis13 . Can you help me again?

I want to convert the Weeknumber to a date example from Week 1(start from Sunday), Month 1(January) then year. So the output goes like this " 01/01/2023 - 01/07/2023 "
Please see example below... Thank you very much

Convert Weeknumber from this

1675544502188.jpeg



To this.

1675544540455.jpeg
 
Upvote 0
Sorry, I would like to point out that this is a completely different case.
In these cases, to have even a minimum of visibility in the Forum, I suggest starting a new thread with a new appropriate title.
 
Upvote 0

Forum statistics

Threads
1,215,455
Messages
6,124,935
Members
449,195
Latest member
Stevenciu

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