Pasting same cell on different rows as value is replaced - vba

This sort of follows up from my previous few questions on the same workbook.
I have two sheets, the first being Car Search, which contains a form (NOT a VBA form, just a normal table that appears like a form) to fill in. The second sheet is Raw Data, and will contain all the information entered in the Car Search sheet. It will be displayed row by row (see 2nd image).
In the Raw Data sheet, I am using the formula =""&'Car Search'!B3 to copy the contents of cell B3 in the Car Search spreadsheet.
My question is: If I had a new Car ID value, how can that automatically be entered into the row below?
Essentially, I am trying to use the form to capture all data for new cars coming in, and then I would like all that data to appear in the second sheet in their respective rows/columns.
Any help much appreciated! :)

EDIT:
Good news!
You need to use VBA:
Sub Range_Copy_Examples()
Worksheets("Car Search").Range("B3").Copy Worksheets("Raw Data").Range("=OFFSET(Sheet3!B1,0,0,COUNTA(B1:B300)+1,1)")
End Sub
However there is a small bug where it keeps pasting across past values, so I have suggested an alternative macro below
Re-edit:
A more mechanical way to make macro work (hopefully someone can improve on it) looks like this:
Sub Macro1()
Sheets("Car Search").Select
Application.CutCopyMode = False
Selection.Copy
Sheets("Raw Data").Select
ActiveCell.Offset(1, 0).Range("A1").Select
ActiveSheet.Paste
Worksheets("Car Search").Activate
End Sub
This works as follows:
in Car Search, have cell B3 selected the whole time
in Raw Data, select the cell with the last value in the column where you want you Car Search!B3 data pasted (you only have to do this once)
press Run on the macro (easy enough to just record one yourself)
go back to Car Search and change the value of B3, press Ctrl-Enter to keep the same cell selected after changing value, then press the same macro button without changing a thing.
If someone could add so that when pressing Ctrl-Enter on Car Search!B3 the Raw Data gets automatically added without having to manually run the macro, it would be fully automated!

Related

Refering to Table cell in Macro

So, I am relatively new to VBA and Programming as a whole,
I know in Excel Formulae, Rather than refer directly to a Cell ($B$27) you can refer to the Column name instead, (#[Condition]).
Now I am aware that this only works on "linear" tables, the formulae will only work on and affect the row its in, but for the table i am working on this is fine.
My question is, is there a way to refer to this inside VBA?
I am trying to create a function that takes the value of a "Condition" Cell and if this is "Other" it will open a custom User form with 3 buttons that allow the user to select the reason why the Condition is "other"
Depending on the button click, the Value of another Cell in the same table (Works Completed) will be changed to what ever the reason they click.
(E.G, user clicks "To be Repaired", the value of "Works Complete" will be changed to "For Repairs"
This currently only works when referred to a Cell directly ($B$27)
Whenever you have a question, concerning the translation of a manual action in Excel to VBA the best answer is:
Start the macro recorder, do the manual action and check yourself.
This is a sample of a recorded macro, selecting Table1, Column3:
Sub Macro1()
Range("Table1[[#Headers],[Column3]]").Select
ActiveCell.FormulaR1C1 = "Testing"
Range("C2").Select
End Sub

clear cell value if condition is met vba

I am trying to use pivot table to generate charts but then I wanted to incorporate vba codes to clear values if certain string is selected, so I don't want to generate charts if certain string is selected.
Now, my vba codes uses a lot of lookup functions which I should incorporate the iferror statement back then but again I feel like its too late for me to go back and will just take more time to fix each vlookup function I used. Now, since I am only getting stuck on this portion, I am just going to post the codes for this portion.
How pivot table and charts work is that the user selects zip code and/or county and it will calculate vlaues and graph will appear so I can monitor monthly data. Each of the 3 selection button has N/A which is supposed to not return any value so chart won't graph, similar to reset button. I just tested if I select zipcode as N/A but the codes failed so I haven't expanded my test codes to county and territory. Also (All) is different from N/A as for (All), I am calculating everything, as the whole book of business.
I tried to copy and paste the pivot table as values and see if it will work, and it just won't execute, and when I pressed F8, it looks like it skips the range selection and selection.clearcontents part and jumps to the end.
Sub test()
'take out n/a
Dim find As String
find = "N/A"
Select Case find
Case Cells(2, 2).Value = find
Range("E14:R14").Select
Range("E43:R43").Select
Range("E73:R73").Select
Selection.ClearContents
End Select
End Sub

VBA Active X button to take user to first cell of updated row

I have a spread sheet which has a button that transfers all the entered data into another sheet. I have then made a second button that takes you to this log should you want to view it, however it takes you too the last cell filled. The log has a lot of columns so i want to make the 'go to log' button to take you to the first cell in the last row that was filled.
all i have at the moment is a simple formula to take you there.
Private Sub CommandButton2_Click()
ThisWorkbook.Sheets("Log").Activate
End Sub
If you are sure that your code is taking you to last Cell filled, and you are expecting the control to go to the first cell of the row then below piece will do.
Cells(ActiveCell.Row, 1).Select

External Data Pull: Pull more specific data or change macro based on data

This question is somewhat difficult to explain, so bear with me.
I am pulling data from a large table for my company and am trying to create a macro to make this data easier to read/understand. The data that is on the site changes every day based on what caused certain failures in our plant, which causes my macro to analyze data that isn't there or wrong cells (due to rows getting shifted/moved/added/removed). Because I don't think that was really clear, here is an example:
The macro says to select cells J5, J13, and J25. These were, when I was creating the macro, the values I wanted to be put in a list. However, when I pulled the data and ran the macro today, these values were in different spots on my sheet (the value for cell J13 is now in J12). This completely messes up all of the analysis and renders my macro / data pull useless.
Is there a way to have the macro select the data more intelligently? Perhaps have it check for the group name, then select the value from the cell next to it? I wish I could word this better... Thanks if you've gotten this far!
Simply put... yes. Here's a code exert for looking for a groupname and getting the adjacent cell:
Dim Group1Range As Range
'Look in ThisWorkbook
With ThisWorkbook
'Look in Sheet1
With .Sheets(1)
'Look in Column I
With .Columns("I:I")
'Find the text Group1
Set Group1Range = .Find(What:="Group1").Offset(0, 1)
End With
End With
End With
'Indicate the address of the found range
Debug.Print Group1Range.Address
End Sub
Now here are ways that you can improve your question:
Explain how you know that cell J13 is no longer valid, and that J12 is now.
Give us some sample data.
Give us your code.
Tell us what your end result would be, possibly with an example.

Excel macro for automatic data entry

I need a macro to help me with data entry in Excel. Basically I want sheet 1 for data entry, and sheet 2 for the data that are entered. Sheet 1 will only have one row for data entry, and once that row is filled you hit enter. The row is automatically added to the table in sheet 2, and the row is cleared on sheet 1. Now you are ready to enter another entry in sheet 2.
So to summarize sheet 2 will have multiple rows for the data entered, and sheet 1 will only have 1 row because it automatically clears it's row after each entry.
Is something like this possible?? If you guys can post some code for me it would really help, and keep in mind I have never programmed in VBA before. Thanks in advance!!
Place a button on your sheet 1, then put this macro into a regular code module and attach it to your button. Assuming you are entering values across row2 (row1 being titles or such), then this would transfer row2 data to the next empty row on sheet2:
Sub Transfer()
Rows(2).Copy Sheets("Sheet2").Range("A" & Rows.Count).End(xlUp).Offset(1)
Rows(2).ClearContents
End Sub
I'm not totally sure of the use-case, but have you considered using Excel UserForms instead.
The input would be a form that actually appears in front of the user which would collect input. When they hit the enter button, you could have underlying code to update the main sheet, Sheet 2.
http://www.excel-vba-easy.com/vba-userform-excel-vba.html
You could also use the database form. set up your database sheet then Data > Form (in 2003)
In order not to have to "click" on a button, I would suggest to look into this function:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
End Sub
This macro will run every time something in your sheet has changed.
It might be that you have to check if there is data in cell A1, as this VBA might be triggered both after hitting enter and after the data has been transported to the other sheet.