Insert data before Offset

Livin404

Well-known Member
Joined
Jan 7, 2019
Messages
743
Office Version
  1. 365
  2. 2019
Platform
  1. Windows
I'm trying to add data "DATE:" to an offset in a formula. The end result would be "DATE: WEDNESDAY NOVEMBER 18 2020".

For briefness I only included a couple of lines which I believe where the edit should go. I tried using different variations of adding this piece
Excel Formula:
.Resize(1).Offset(-1).Value = "DATE:"
with "&", and it either errored out or inserted "DATE:" and ignored the actual date.

VBA Code:
For x = .Areas.Count To 1 Step -1
      If x > 1 Then .Areas(x)(1).EntireRow.Insert
      With .Areas(x)
        .Resize(1).Offset(-1).Value = .Value
         .Resize(1).Offset(-1).Replace "(*", Year(Now), xlPart, , , , False, False
        .Resize(1).Value = "DESTINATION"
 

Excel Facts

Bring active cell back into view
Start at A1 and select to A9999 while writing a formula, you can't see A1 anymore. Press Ctrl+Backspace to bring active cell into view.
You would need something like this:
VBA Code:
Sub Insert_Date()
'Modified 11/18/2020  11:33:20 PM  EST
Cells(1, 1).Value = "Date:" & Format(Date, "DDDD MMMM DD YYYY")
End Sub
 
Upvote 0
You would need something like this:
VBA Code:
Sub Insert_Date()
'Modified 11/18/2020  11:33:20 PM  EST
Cells(1, 1).Value = "Date:" & Format(Date, "DDDD MMMM DD YYYY")
End Sub
I appreciate your input but I needed the "DATE:" in front of the date. It needs to be part of this VBA which I got from a gentleman on this site. I think it should be on the same line as :
Excel Formula:
.Resize(1).Offset(-1).Replace "(*", Year(Now), xlPart, , , , False, False
Thank you.


VBA Code:
Sub Outbound_Fids()
  Dim x As Long
  With Sheets("Outbound FIDS").Range("A2", Sheets("Outbound FIDS").Cells(Rows.Count, "A").End(xlUp)).SpecialCells(xlConstants)
    For x = .Areas.Count To 1 Step -1
      If x > 1 Then .Areas(x)(1).EntireRow.Insert
      With .Areas(x)
        .Resize(1).Offset(-1).Value = .Value
        .Resize(1).Offset(-1).Replace "(*", Year(Now), xlPart, , , , False, False
        .Resize(1).Value = "DESTINATION"
        .Offset(1).Replace "*(", ""
        .Offset(1).Replace ")*", ""
      End With
    Next
  End With
End Sub
 
Upvote 0
Maybe
VBA Code:
.Resize(1).Offset(-1).Value = "DATE: " & .Value
 
Upvote 0
Thank you for your response, I tried right after the first resize line and in-place of that line and I ended up getting a type mismatch error run-time error 13. I'm sure the line that has to be adjusted is one of the two resize lines.
 
Upvote 0
I understand, I tried using "Watch" and there looks like there is some sort mismatch on either side of the equals. In any case I provided an image of what it started out with. Never mind the cell fills and borders they're from another VBA. The word DATE followed by a space "DATE: " I hope to get in front of the date as seen in the image DATE: THURSDAY NOVEMBER 19 2020.
I have one other question after I/we sort this out. I will need to have those dates in yellow and aligned to the left. Would it be better to do it while I'm in this code or should I create a new VBA to sort that out, or is it even an option. Thank you,
72 hr to FIDS.JPG
 
Upvote 0
What happens when you run the code?
 
Upvote 0
What happens when you run the code?
I get that mismatch error, then I selected the debug and you see the results in the image. Thank you for the quick response.
 
Upvote 0
Do you have two or more contiguous cells that have data in them?
 
Upvote 0

Forum statistics

Threads
1,214,522
Messages
6,120,020
Members
448,939
Latest member
Leon Leenders

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