Writing to a specific Row

Pacman52

Active Member
Joined
Jan 29, 2009
Messages
428
Office Version
  1. 365
Platform
  1. Windows
Hi all so I have a worksheet with 100's of rows filled in via a Userform. I was just adding some references to the worksheet and noticed there are two rows that have not written over the formatting I set in the 'writedatatoworksheet' sub in two of the columns (strangely on every other row it has been formatted correctly)

I've checked the worksheet formatting and also all the subs formatting and its all ok but again its just these two row columns that are wrong.

In order to quickly fix the two problem rows I thought a quick way would be to simply create a new sub that writes to a specific row, In my case row 17 and row 71 columns 3 and 4 and re enter the relevant data.

What I have at the moment is
VBA Code:
Private Sub WriteDataToSheetSales()

With sh4Sales.Range("A3").Offset(m_currentRow)

.Cells(1, 3).Value = txbTotalSaleAmount.Value

.Cells(1, 4).Value = txbPostagePaid.Value

End With

End Sub

Is there a way to reference the actual row number I want to correct?

Thanks Paul
 

Excel Facts

Shade all formula cells
To shade all formula cells: Home, Find & Select, Formulas to select all formulas. Then apply a light fill color.
How are you calling this sub? Unless you're calling it from the other sub and the variables are set globally it won't work in its current form. For example, how are you getting the value of m_currentRow?
 
Upvote 0
Hi thanks for the reply - sorry I just pasted a shortened version of the subs but yes the variables are set globally and everything works fine when writing to the sheet. There is in excess of 350 rows populated with data and its only the two rows listed 17 & 71 that are not formatted correctly which may have been down to me simply typing something odd that would upset the formatting for some reason. I will be running through the subs to double check but for now I just need a quick fix hence my original post.

Paul
 
Upvote 0
If you just need a quick fix you can reference the cell directly:
VBA Code:
sh4Sales.cells(17,3).value=txbTotalSaleAmount.Value
sh4Sales.cells(17,4).value=txbPostagePaid.Value
 
Upvote 1
Solution
Hi so sorry for the delay in responding I’ve been travelling and not had any connection.

Thank you for the code, I haven’t tried it yet but I’m sure it will do the trick for what I need.

Paul
 
Upvote 0

Forum statistics

Threads
1,224,811
Messages
6,181,081
Members
453,021
Latest member
Justyna P

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