VBA assistance - form data not posting to next cell, continues to overwrite

KayWill

New Member
Joined
Jan 22, 2015
Messages
36
I have another issue where I'm stumped, I've used this same code on 5 different other forms and it performs as it should on them but on my current worksheet, it continues to "overwrite" the previous data instead of moving to the next line in the table. My code is as follows:

Code:
On Error Resume Next

' Write data to worksheet
    RowCount = Worksheets("CoreConSummary").Range("AH1").CurrentRegion.Rows.Count
    With Worksheets("CoreConSummary").Range("AH1")
        .Offset(RowCount, 0).Value = Me.txt_SiteWrk.Value
        .Offset(RowCount, 1).Value = Me.txt_VESTIBULE.Value
        .Offset(RowCount, 2).Value = Me.txt_CHKOUT.Value
        .Offset(RowCount, 3).Value = Me.txt_PHOTOLAB.Value
        .Offset(RowCount, 4).Value = Me.txt_MINCLINIC.Value
        .Offset(RowCount, 5).Value = Me.txt_RETAIL.Value
        .Offset(RowCount, 6).Value = Me.txt_SOA.Value
        .Offset(RowCount, 7).Value = Me.txt_PHARMACY.Value
        .Offset(RowCount, 8).Value = Me.txt_EMPAREA.Value
        .Offset(RowCount, 9).Value = Me.txt_RECVAREA.Value
        .Offset(RowCount, 10).Value = Me.txt_RRMS.Value
        .Offset(RowCount, 11).Value = Me.txt_GENCOND.Value
        .Offset(RowCount, 12).Value = Me.txt_PROFIT.Value
        .Offset(RowCount, 13).Value = Format(Now, "mm/dd/yyyy hh:nn:ss")
    End With

' Clear the form
    For Each ctl In Me.Controls
        If TypeName(ctl) = "TextBox" Or TypeName(ctl) = "ComboBox" Then
            ctl.Value = ""
        ElseIf TypeName(ctl) = "CheckBox" Then
            ctl.Value = False
    End If
    Next ctl
      
End Sub

The only difference with this form is that I change the numbers entered into percentages, code example as follows:

Code:
Private Sub txt_SiteWrk_AfterUpdate()
txt_SiteWrk.Value = Format(txt_SiteWrk.Value / 100, "0.0%")
End Sub

but this 'should' have nothing to do with the information from the user pasting in on a separate line what am I missing?
 

Excel Facts

Can Excel fill bagel flavors?
You can teach Excel a new custom list. Type the list in cells, File, Options, Advanced, Edit Custom Lists, Import, OK
Add 1 to RowCount to make it the next empty line.

RowCount = Worksheets("CoreConSummary").Range("AH1").CurrentRegion.Rows.Count + 1
 
Upvote 0
Add 1 to RowCount to make it the next empty line.

RowCount = Worksheets("CoreConSummary").Range("AH1").CurrentRegion.Rows.Count + 1

Hi AlphaFrog, finally got it working. Just to update you, when I placed the '+1' after count, it dropped it too far down which was outside of the table. Don't know why Excel is being so quirky with me today but I did get it to work by changing my code to the following:

Code:
On Error Resume Next

' Write data to worksheet
  Set ws = Worksheets("CoreConSummary")
  LRow = ws.Cells(Rows.Count, 34).End(xlUp).Offset(0, 34).Row
    
    With ws
        .Cells(LRow, 34).Value = Me.txt_SiteWrk.Value
        .Cells(LRow, 35).Value = Me.txt_VESTIBULE.Value
        .Cells(LRow, 36).Value = Me.txt_CHKOUT.Value
        .Cells(LRow, 37).Value = Me.txt_PHOTOLAB.Value
        .Cells(LRow, 38).Value = Me.txt_MINCLINIC.Value
        .Cells(LRow, 39).Value = Me.txt_RETAIL.Value
        .Cells(LRow, 40).Value = Me.txt_SOA.Value
        .Cells(LRow, 41).Value = Me.txt_PHARMACY.Value
        .Cells(LRow, 42).Value = Me.txt_EMPAREA.Value
        .Cells(LRow, 43).Value = Me.txt_RECVAREA.Value
        .Cells(LRow, 44).Value = Me.txt_RRMS.Value
        .Cells(LRow, 45).Value = Me.txt_GENCOND.Value
        .Cells(LRow, 46).Value = Me.txt_PROFIT.Value
        .Cells(LRow, 47).Value = Format(Now, "mm/dd/yyyy hh:nn:ss")
    End With

I thought that maybe is because my paste were in cells 34 that I needed to use the .Cells line of code to direct the paste to the correct columns. It's working and I want to say THANK YOU very much for responding. Hopefully my notes above will help others having similar challenges.:biggrin:
 
Upvote 0
Re: SOLVED - VBA assistance - form data not posting to next cell, continues to overwrite

See previous response from me to see how this was resolved.
 
Upvote 0

Forum statistics

Threads
1,214,944
Messages
6,122,387
Members
449,080
Latest member
Armadillos

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