Is there a way or formula that could move a certain row to a different sheet by just typing in the criteria and pressing enter?
Like if I have 3 sheets and one of the columns on each sheet was called status, and in this column I type COMP, could it move all the information to a sheet called COMP sheet?
Insert this code on your worksheets
Private Sub Worksheet_Change(ByVal Target As Range)
If (Range("A1").Value = "COMP") Then ' Replace "A1" for your cell that will contain COMP
ActiveSheet.Range("1:1").Copy _ ' Replace 1:1 by your souce row
Destination:=Worksheets("COMP").Range("2:2") 'replace 2:2 by your dest row
End If
End Sub
When the user changes any value in the Worksheet, if the value of "A1" is "COMP", the row you chose (1 in the example) is copied into your destination row (row 2 in the example) in worksheet COMP.
You can build a VBA Macro that does all of the moving for you, but that would require the user to manually run it, not just typing COMP in a cell. You can also have it update automatically without the user pressing COMP and enter by using a formula that references the other worksheets (but then it will always be there).
=Sheet1!A1
The above code will reference the top left cell in the Worksheet 'Sheet1'.
Related
I am looking for a Excel VBA code to select the resulting Form address on Sheet 2 from the set of States on Sheet 1, but I need to copy the cell and paste it to retain the existing hyperlink attached to Form.
The only common data is the States.
I used INDEX MATCH but it only gets the word "Link" without the hyperlink itself.
I couldn't actually Select the cell, then copy and paste it.
Sheet 1
Sheet 2
I tried but don't have any idea how. As long when I choose what's selected on Sheet2 State (e.g Sheet2 Cell D2 - Alabama), the corresponding Form Link (e.g Sheet1 Cell B3 - Link) will be selected and copied through the Macro.
Sub test2()
Dim link As Range
Set link = Range("INDEX(Sheet1!B:B,MATCH(Sheet2State,Sheet1State,0),0)))")
Set s1 = Range("D5")
link.Copy
s1.PasteSpecial
End Sub
I need some help for my Excel sheet,
I have the first sheet and this is blank
and on the seconde sheet i have a list and in the column D i can change the value starts from 1.
And when i changed in the column a cell then it should copy the row to the first sheet.
thanks
Regards
It is not clear for me what you want to do. If you want VBA to copy the row automatically, you should go to the module of the corresponding Worksheet in the VBA editor (in the list of the Wroksheets on the left, just double-click the Worksheet to open up the module associated with it). After that, write an event handler:
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Column = 4 Then
ActiveSheet.Rows(Target.Row).Copy Worksheets("Sheet1").Rows(whichRowYouNeed)
End If
End Sub
you should also write a routine to determine the 'whichRowYouNeed'
It may be the end of the filled range on Worksheet1
Hey sorry for my bad statement, i try it again :)
The first sheet is blank,
The Second sheet is that:
When i add a number in column D then I want to copy this row, in that case row 8, copy to the first sheet starting from row 5.
I hope now it is better to understand
I have a button driven macro that copies a range of cells to the clipboard (so I can place in other documents):
Sub Button2_Click()
'
' Button2_Click Macro
Range("A1:p43").Copy
End Sub
Form time to time I need to either add or delete a row in that range in the worksheet. What I need is for the copy range to expand (or contract) to the number of rows containing the values. Note: the columns will not adjust, just the rows.
If the copy range is a contiguous range of values with a blank column in column Q and a blank row below row 43, you can use the CurrentRegion property like this:
Range("A1").CurrentRegion.Copy
It's basically the same as clicking A1 and then using Ctrl-Shift-Down arrow and Ctrl-Shift-Right arrow.
Let's say I have three sheets in Excel. Sheet 1 is the Master sheet, sheets 2 and 3 contain different sets of information with the same headers that feed into the table in the master sheet. Is there a way to make it such that I could edit information in sheet 1 and sheet 2 will change AND vice versa so I can edit info in sheet 2 that will update the master sheet?
You could solve it by having Vlookup-formulas in your Master sheet. That way, if you change anything in sheet 2 and 3 the Master will automatically be updated.
If the user changes anything in the Master sheet, you will have to build logic in VBA on that. One way to go is to format the Master sheet so that there is something that helps the VBA know what the formula should be in the edited cell, and also to know from where the data should come. Loosely one could set up the Master sheet like this:
Row 1 is hidden and contains the template formulas
Row 2 is hidden and is completely empty (this will make less problems with filtering)
Row 3 contains headers
Row 4 and down contains the data, using the formulas define in row 1
Add the Change event on the Master sheet, that sees if the changed cell was one with a formula. If so, it will examine the template formula to identify from where the data should come. Then it will update that cell in Sheet 2 or 3 with the new value that is entered in the Master sheet. After this, it will overwrite the value manually entered in the Master sheet with the formula from the template row.
The big job here is to write a parser that understands from which cell the vlookup will get it's value.
One thing that I overlooked is that the CHANGE event is triggered only ONCE if the user pastes several cells in one go. The TARGET will then contain several rows or columns.
So this is some kind of skeleton using the above idea...
Option Explicit
Dim ChangeEventDisabled As Boolean 'Flag for disabling the Change event
Public Sub Disable_ChangeEvent()
ChangeEventDisabled = True
End Sub
Public Sub Enable_ChangeEvent()
ChangeEventDisabled = False
End Sub
Sub Worksheet_Change(ByVal Target As Range)
Dim updatedValue As Variant
Dim SourceCell As Range
'While the MasterSHeet is populated intially, we don't want this event to do anything
If ChangeEventDisabled Then
'There are chenges being done in teh sheet that should not trigger updates of the source-sheets.
Else
'Only run the code if it was a data-cell that was changed
If Target.Row > 3 Then
'We are in the rows containg data
'Did the changed cell contain a Vlookup formula before the user changed the cells value?
If UCase(Cells(1, Target.Column).Formula) Like "=VLOOKUP(*" Then
'A vlookup normally populates this cell.
'To know from where the data normally comes, I will need to put back the formula in the changed cell.
'So, first save the new value that we will write in the source cell
updatedValue = Target.Value
'Insert the formula again in the cell
'As we will now CHANGE a cell in the Masterr sheet, a Change event will trigger. Disable it temporarily
Disable_ChangeEvent
Cells(1, Target.Column).Copy Destination:=Target
Enable_ChangeEvent
'Find out from which cell the data is being fetched by the Vlookup
Set SourceCell = MyMagicParsing(Target)
'Update the source-cell with the new value
SourceCell.Value = updatedValue
End If
End If
End If
End Sub
Function GetSourceCell(Target As Range) As Range
'This function should decipher the formula in the cell Target, and figure out from where
'the data is actually coming. It shoudl return the range which is the source of the data.
'As I dont know how to do that quickly, I just hardcode the cell that is the source.
GetSourceCell = Worksheets("Sheet2").Cells(67, 3)
End Function
I have 5,000 part numbers contained on one sheet of an Excel workbook (Part Numbers), ranging from cell A1:A5000. I want to find a way to click on any one of those part numbers and have it automatically populate into cell D7 on another sheet of the same workbook (Price Sheet). What is the easiest way to accomplish this task?
To do it that way, you will have to write VBA code to catch every SheetSelectionChange event to see if the new selection range is in your cells A1:A5000. And then if it is, execute the VBA code to fill OtherSheet!D7.
If I recall correctly, the VBA code to do this would look something like this:
Private Sub WorkSheet_SelectionChange(ByVal Target As Range)
'Check if it is in the range A1:A5000
If Target.Column = 1 And Target.Row <= 5000 Then
'get the target worksheet
Dim TargetWS As Worksheet
Set TargetWS = Sheets("OtherSheetsName")
'copy the value of the just selected cell to D7 on the target WS
TargetWS.Cells(7, 4).Value = Target.Value
End If
End Sub
(Oops, forgot about the need for "SET" in VBA.)
You can do this without VBA:
Select the partnumbers A1:A5000 and type PartNumbers in the Name Box (to the left of the formula bar) and press carriage return (OartNumbers should now be visible in the Name Box whenever you select a1:a5000
Now go to cell D7 on Price Sheet, and use Data Validation-->List and enter =PartNumbers in the Source box
Now you can select any of the 5000 part numbers from the dropdown in cell D7