How to offset and merge columns and enter value in merged columns?

Dave Smith

New Member
Joined
Jul 5, 2021
Messages
32
Office Version
  1. 2016
Platform
  1. Windows
Hi,

I am stuck at one point in vba and i am here to find solution.

I am trying to write program as explained below :
I want to find last row in the sheet (sheet name: "Sheet1") and select the next two rows using offset command and then it should merge column (from A1 to E1) and enter value "Designated value"

I am able to write code for finding the last row and offset it but i am not able to figure out how to merge columns.
The data from range A10 to A15 will be varied as the value enter in the shift cell .

pl. find my code below

Sheet1.Range("A10").End(xlDown).Offset(2, 0).Value = "Designated value"

Any help will be appreciated .

Dave Smith.
 

Attachments

  • Screenshot 2022-01-17 092036.png
    Screenshot 2022-01-17 092036.png
    18.3 KB · Views: 15

Excel Facts

Do you hate GETPIVOTDATA?
Prevent GETPIVOTDATA. Select inside a PivotTable. In the Analyze tab of the ribbon, open the dropown next to Options and turn it off
Hi,

I am stuck at one point in vba and i am here to find solution.

I am trying to write program as explained below :
I want to find last row in the sheet (sheet name: "Sheet1") and select the next two rows using offset command and then it should merge column (from A1 to E1) and enter value "Designated value"

I am able to write code for finding the last row and offset it but i am not able to figure out how to merge columns.
The data from range A10 to A15 will be varied as the value enter in the shift cell .

pl. find my code below

Sheet1.Range("A10").End(xlDown).Offset(2, 0).Value = "Designated value"

Any help will be appreciated .

Dave Smith.
I am not knowing how to merge the columns after using offset command
 
Upvote 0
VBA Code:
Option Explicit
Sub insert_value()
Dim cell As Range
Set cell = Cells(Rows.Count, "A").End(xlUp)
    If cell.MergeCells And cell.Value = "Designated value" Then Exit Sub
    With cell.Offset(2, 0).Resize(, 5)
        .Merge
        .HorizontalAlignment = xlCenter
        .Value = "Designated value"
    End With
End Sub
 
Upvote 0
Solution
VBA Code:
Option Explicit
Sub insert_value()
Dim cell As Range
Set cell = Cells(Rows.Count, "A").End(xlUp)
    If cell.MergeCells And cell.Value = "Designated value" Then Exit Sub
    With cell.Offset(2, 0).Resize(, 5)
        .Merge
        .HorizontalAlignment = xlCenter
        .Value = "Designated value"
    End With
End Sub
Thank you so much bebo021999 for helping me it worked for me :)
 
Upvote 0

Forum statistics

Threads
1,214,952
Messages
6,122,457
Members
449,083
Latest member
Ava19

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