Offset property only works for column 0

morfex

New Member
Joined
Jul 16, 2009
Messages
3
I have a workbook with several userforms. When a user fills out the form, the data in inserted into a series of columns in a single row. The next time they use the form, Excel adds the data to the next available row.

Now I want to add the ability for them to edit one of their entries via a form. This time, when the click on the first cell in the row, the userform loads. I've added the following code to the form on Activate:

Private Sub UserForm_Activate()
ActiveSheet.Unprotect
frmEliteEdit.txtGuestName.Value = tbl.Offset(0, 2).Value
frmEliteEdit.txtSaleDate.Value = tbl.Offset(0, 11).Value
End Sub

When the form opens, I want the textboxes and other fields on the form to be populated with the values from that row. So, if they click on the first cell in row 12, the GuestName field should contain the value of the 3rd cell in the row, and SaleDate should contain the value from the 12th cell in the row. However, it simply leaves the form fields blank.
If I change the Offset to (0, 0), the form does load the textbox with the data from the first cell, but it will not work for data in any other columns.

What am I doing wrong?
 

Excel Facts

How to fill five years of quarters?
Type 1Q-2023 in a cell. Grab the fill handle and drag down or right. After 4Q-2023, Excel will jump to 1Q-2024. Dash can be any character.
Sorry about that. When they click on the cell to launch the edit form, the cell remains selected. The code should read:

Private Sub UserForm_Activate()
ActiveSheet.Unprotect
frmEliteEdit.txtGuestName.Value = ActiveCell.Offset(0, 2).Value
frmEliteEdit.txtSaleDate.Value = ActiveCell.Offset(0, 11).Value
End Sub
 
Upvote 0
Which event are you using to launch the form?

I tried it with:

Code:
Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
    If Target.Column = 1 Then
        frmEliteEdit.Show
    End If
End Sub

And your code worked fine
 
Upvote 0
Weaver,

Thanks so much for your help. Turns out I wasn't writing the code incorrectly, but on my worksheet each row contained many merged cells and this code doesn't appear to be able to jump across merged columns. So telling it to go from column 3 (merged 3-10), then column 11 (merged 11-19) did not work.

I rebuilt the spreadsheet without merging any cells in these rows and it works like a dream.

Thanks again!
 
Upvote 0

Forum statistics

Threads
1,223,164
Messages
6,170,444
Members
452,326
Latest member
johnshaji

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