Getting data to go to the correct columns

loplop

New Member
Joined
Mar 2, 2020
Messages
10
Office Version
  1. 2013
Platform
  1. Windows
I am working on a userform for work and I am having some issues with data where I would like it to go. We would be using this at a station where we would be recording downtime for our operation line as it's running. Most of the time if we have any downtime, it would only be once per lot we are running. But we have the chance to run into multiple downtime situations. On the userform I would have them labeled as downtime 1, downtime 2 and downtime 3.
So I have downtime 1 star time Command button set to record to the next available column D.
Private Sub CommandButton3_Click()
Dim ws As Worksheet
Dim nextRow As Long

' Set the worksheet
Set ws = ThisWorkbook.Sheets("Data")

' Find the next available row in column D
nextRow = ws.Cells(ws.Rows.Count, "D").End(xlUp).Row + 1

' Add current time to the next available row in column B
ws.Cells(nextRow, "D").Value = Now

' Show the date and time in TextBox5 on UserForm1
UserForm1.TextBox5.Value = Now

End Sub

Lets say that data goes to Row 1 , Column D.
Now on the next lot I might have 2 times that I would have to record downtime. Using downtime 1 command button again, it will go to Row 2, Column D.
BUT I have downtime 2 to go Column G, but if I click it, the data would be recorded in Row 1, Column G, when I need the data to be in Row 2, Column G.

How would you right the VBA to not only go to the next available Column, but go into the Row that you are using at the time.

Sorry, this might be long and wordy, but if you need more info to help...let me know.
 

Excel Facts

Highlight Duplicates
Home, Conditional Formatting, Highlight Cells, Duplicate records, OK to add pink formatting to any duplicates in selected range.
It would be easier to help if you could upload a copy of your file which includes the userform to a free site such as www.box.com or www.dropbox.com. Once you do that, mark it for 'Sharing' and you will be given a link to the file that you can post here. Explain in detail what you want to do referring to specific cells, rows, columns and sheets using a few examples from your data (de-sensitized if necessary).
 
Upvote 0
Ok. Here is a link to the sheet that I am working on:


If I click CommandButton1 on Sheet 1, it takes me to my userform to fill out.
So I start by clicking Start Lot Time.
Then I enter a Lot Number.
Now...if we are running the lot and I have downtime, I would click Start Downtime 1 and the time will start.
When the Downtime is done I click End Downtime1.
When I am done...all information is in the desired row where I would want it.
excel1.PNG


The problem then comes in, that if we move to the next lot and repeat the steps above. Everything is fine. BUT if I have to put another set of start and stop for downtime. So I would click the downtime2 buttons. But instead of putting the data in row three where I am working, it puts the data up on row 2, where it finds the next available column that I dictated.
.
excel2.PNG


My question is how do I get, all my data to be in the same row??
 
Upvote 0
Click here for your file. You will have to define the variable "nextcol" in the CommandButton5_Click event otherwise you will get an error.
 
Upvote 0
Click here for your file. You will have to define the variable "nextcol" in the CommandButton5_Click event otherwise you will get an error.
THANK YOU! The downtime lines are working as needed, but now my lot number is always one row below.
 
Upvote 0
In the TextBox3_KeyDown event, replace this line of code:
VBA Code:
lastRow = .Cells.Find("*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row + 1
with this line:
VBA Code:
lastRow = .Cells.Find("*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row
 
Upvote 0

Forum statistics

Threads
1,224,821
Messages
6,181,163
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