I have inherited a workbook that has suffered months of abuse (poor data entry, poor cut and paste, duplications, etc). I have nearly finished sorting the data but to prevent similar problems I am trying to automate some of the process. I am new to VBA and cannot figure out why my code isn't working. There are several worksheets that track an application through our new client process. Each worksheet has the same fifteen columns, metadata in the first 10 rows (=sum counts) and headers in the 11th row. When we receive interest in joining our organisation some simple data is entered into columns A-D and L-O inclusive. I want a particular row to move to the next worksheet when a date is entered to indicate a step in the process has been completed. For example when a client returns an application form, the date is entered into column G and the specific row is moved to the next worksheet and deleted from the original. The date entry works but columns L-O are not being copied. HELP!
The code I'm using is:
Private Sub Worksheet_Change(ByVal Target As Range)
If Not Intersect(Target, Range("G12:G100" & Range("A" & Rows.Count).End(xlUp).Row)) Is Nothing And Target.Cells.Count = 1 Then
If IsDate(Target.Value) = True Then
Range(Cells(Target.Row, "A"), Target).Copy Sheets("Awaiting Interview").Range("A" & Rows.Count).End(xlUp).Offset(1, 0)
Target.EntireRow.Delete
End If
End If
End Sub
Thank in advance.
AlVBA
Related
I am trying to create a log sheet to keep track of a fleet's service. A vehicle can be in service, out of service, or both during each month (in/ out of service 9/1/21 - 9/30/21; in service 9/1/21 - 9/15/21, out of service 9/16/21 - 9/30/21). When the information is changed each month, I want the old row information to be recorded in another sheet with an identical table. Preferably, the row would only be recorded/ moved once all the necessary dates are changed.
.
So ideally, it would somehow wait until all changes to the row are made - I think it would be too complicated to check whether each date cell is properly changed because some can be left empty, but maybe a check if the user is finished updating a row before moving on?
I found this code on a Microsoft forum. It's close to what I need, but not quite. I'm just not 100% clear on the syntax, so I've had a hard time knowing what and how to change things. I changed Range("A:A") to Range("A:J") to look for changes in every column, and Range("A" & a) to Range("C" & a) to at least put data changed in column C to the new column C.
Private Sub Worksheet_Change(ByVal Target As Range)
If Not Intersect(Target, Range("A:J")) Is Nothing Then
a = Sheets("Sheet2").Cells(Rows.Count, "C").End(xlUp).Row + 1
ActiveCell.Offset(-1, 0).Activate
Sheets("Sheet2").Range("C" & a).Value = ActiveCell.Value
ActiveCell.Offset(1, 0).Select
End If
End Sub
I have 7 worksheets which do exactly what I want. I am now being asked for a filter to show specific years. Done. However to look at a year of trend data, I have to manually filter each sheet.
I wouldn't mind going the extra mile, and if it's possible, have a filter in one of these sheets that organises the year in all the other sheets.
I have=YEAR(O9:O29148) on my largest sheet. A8:O8 and everything above is exactly the same on each sheet, every sheet has the same type of data in the same column. The only thing that does change is the unique data itself.
What I want is to have a Year filter (2000-2018) on my dashboard, which will then filter all the worksheets to show the same year, or all data if required.
Is this even possible?
(I do not understand VBA code, but I am capable of inserting it into VBA editor and then running said macro).
Any help would be greatly appreciated, thank you!
Not really knowing a lot about the way your data is set up, I build the following, with this code on the worksheet_change event of the dashboard sheet, where I have E6 controlling the year. I have 3 other sheets with data in column A with year numbers, you can use this as a base. You will need to experiment with your column, on the filter, number most likely.
Private Sub Worksheet_Change(ByVal Target As Range)
Dim wsWorksheet As Excel.Worksheet
If Target.Cells(1, 1).Address(False, False) = "E6" and Target.Cells.Count=1 Then
For Each wsWorksheet In ThisWorkbook.Worksheets
With wsWorksheet
If .Name <> Target.Worksheet.Name Then
If .UsedRange.AutoFilter Then
.UsedRange.AutoFilter 1, Target.Value
End If
End If
End With
Next wsWorksheet
End If
End Sub
Public Sub Filter_Sheets()
Dim i As Long
Dim comboBox As ControlFormat
With ThisWorkbook
Set comboBox = .Worksheets(9).Shapes("Drop Down 229").ControlFormat
For i = 1 To Worksheets.Count
.Worksheets(i).UsedRange.AutoFilter Field:=15, Criteria1:=comboBox.List(comboBox.ListIndex)
Next
End With
End Sub
This is the best fit I have managed to discover. I still get an error (AutoFilter method of Range class failed). However this does work. I am now using a combobox to change the auto filter on all 7 sheets as needed. In order to go back to select all, having "<>" in a cell the dropdown references, works to select all the data again.
I have a set of CSV data copied from a grid in third party program that I want to paste into excel. The data consists of names in the first column and dates/times in the second column. The data is descending order of time and continually updated. The problem is that the grid for whatever reason has a limit of 1000 rows and as it belongs to s third party app, I can’t get the limit increased.
I want to be able to automatically remove duplicate rows based on the name column in the data set and keep the row with the oldest time.
The trickier bit is that I will be continually adding to the excel grid so I need to also check against the existing data in excel and remove any duplicate rows from the data to be pasted.
I want to be able to do this automatically as I will not have enough time to quickly format it manually.
So is there a way to achieve this?
Thanks,
iq
Put this code into the worksheet's private code sheet.
Option Explicit
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Count > 1 Then
On Error GoTo meh
Application.EnableEvents = False
With Cells(1, 1).CurrentRegion
.Cells.Sort Key1:=.Columns(2), Order1:=xlAscending, _
Orientation:=xlTopToBottom, Header:=xlYes
.Cells.RemoveDuplicates Columns:=1, Header:=xlYes
End With
End If
meh:
Application.EnableEvents = True
End Sub
This is triggered by 2 or more cells of data being pasted into the worksheet.
After trying a few different approaches I am stuck. Basically I have a table where a line is completed every 30 mins or so. The User will enter 3 numbers in a row, the next 3 rows are calculated. I would like to use one of the calculated rows as a trigger to copy the entire row to a DB sheet (sheet2). And repeat when the next line is added and so on. I can only seem to get the 1st line to copy across every time.
The sheet is used as a hardcopy batch record so I have shied away from building a FORM. I started with the following, which worked for line 1 (also calling a recorded macro to copy in some header data)
`Private Sub Worksheet_Calculate()
If IsNumeric(Range("$h$9")) Then
If Range("$h$9").Value >= 1 Then
Application.Run "Macro1"
End If
End If
End Sub `
Macro1 just copying some of the header form data (date/time,machine info etc that is only entered once for the sheet & the row described above).
I hope this is clear, any questions please let me know
Welcome to SO
Try using a loop like below? Change the upper limit of i as you want, and maybe use some form of row counter like Cells(Rows.Count, 1).End(xlUp).Row
Private Sub Worksheet_Calculate()
Dim i As Integer
For i = 1 To 9000
If IsNumeric(Cells(i, 8)) Then
If Cells(i, 8).Value >= 1 Then
Application.Run "Macro1"
End If
End If
Next i
End Sub
I need Help!
I am not well versed in VBA or Macros but i cannot find any other way to accomplish what i need to do without using it.
I have a sheet which i will be using to track Purchase orders, and what i need to do is; when i have a row in sheet 1 (Purchase Orders) which has been recieved i.e. the date of receipt has been recorded in column H i need for the entire row to be cut and pasted into sheet 2 (Received orders).
The header takes up the first 7 rows the rows, so i need the macro to look at rows 8-54. Once the received items are removed from sheet 1, i need the row to also be deleted or preferably for the list to be sorted by column A moving the now empty row which has been cut from open for a future entry.
Any help would be greatly appreciated.
The "Record Macro" feature should be enough to do the task you describe.. In Excel 2007, go to the Developer tab in the Ribbon, and select "Record Macro", and perform exactly the steps you are describing. It will record the equivalent VBA code, which you can then execute - or tweak/modify.
I tested this out, here's one way to do it:
Private Sub Worksheet_Change(ByVal Target As Range)
Application.EnableEvents = False
Dim receivedDate As Range, nextOpen As Range, isect As Range
Set receivedDate = Sheet1.Range("H8:H54")
Set isect = Application.Intersect(Target, receivedDate)
If Not (isect Is Nothing) And IsDate(Target) = True Then
Set nextOpen = Sheet2.Range("A1").End(xlDown).Offset(1, 0)
Target.EntireRow.Copy Destination:=nextOpen.EntireRow
Target.EntireRow.Delete
End If
Application.EnableEvents = True
End Sub
This would be pasted into the Sheet1 code. Any time a cell is changed on sheet1, the code checks to see if it's in the critical range that you specified. (H8:H54) If it is, it then checks to see if it's a date. If it is, it then copies the entire row, puts it in the next open row on Sheet2, and deletes the original row. The cells below it will get shifted up so there are no gaps.
Since the code functions on a cell changing event, it disables "Application.EnableEvents" in order to avoid a loop of changing a cell to call an event which changes a cell to call an event... etc.