When I select a value in F2, search for a match in sheet 'LIST' AB23:AV23, for the match…
- User
When I select a value in F2, search for a match in sheet 'LIST' AB23:AV23, for the match found, use the values (omitting all empty cells) in the coloumn from row 24 to row 34 of sheet 'LIST' to search all the sheets with 3 letter names that contain matches in their column D from row 6 downwards then dispaly the row values as in the vba code below.
Sub AllServicesResults() ThisWorkbook.Worksheets("ADMIN RESULTS").Unprotect Password:="edit" Application.EnableEvents = False Dim ws As Worksheet Dim adminResults As Worksheet Dim lastRow As Long Dim i As Long Dim pasteRow As Long ThisWorkbook.Worksheets("ADMIN RESULTS").Range("A7:K300").ClearContents Set adminResults = ThisWorkbook.Sheets("ADMIN RESULTS") pasteRow = 7 For Each ws In ThisWorkbook.Worksheets If Len(ws.Name) = 3 Then lastRow = ws.Cells(ws.Rows.count, "B").End(xlUp).row For i = 6 To lastRow If ws.Cells(i, "B").Value = "Service" Then adminResults.Cells(pasteRow, 1).Value = ws.Cells(1, "B").Value adminResults.Cells(pasteRow, 2).Value = ws.Cells(i, "B").Value adminResults.Cells(pasteRow, 3).Value = ws.Cells(i, "C").Value adminResults.Cells(pasteRow, 4).Value = ws.Cells(i, "D").Value adminResults.Cells(pasteRow, 5).Value = ws.Cells(i, "E").Value adminResults.Cells(pasteRow, 6).Value = ws.Cells(i, "F").Value adminResults.Cells(pasteRow, 7).Value = ws.Cells(i, "G").Value adminResults.Cells(pasteRow, 8).Value = ws.Cells(i, "H").Value adminResults.Cells(pasteRow, 9).Value = ws.Cells(i, "I").Value adminResults.Cells(pasteRow, 10).Value = ws.Cells(i, "J").Value adminResults.Cells(pasteRow, 11).Value = ws.Cells(1, "J").Value pasteRow = pasteRow + 1 End If Next i End If Next ws ThisWorkbook.Worksheets("ADMIN RESULTS").Range("J5").Value = "ALL SERVICES CURRENTLY DUE" Application.EnableEvents = True ThisWorkbook.Worksheets("ADMIN RESULTS").Protect Password:="edit" End Sub
- Assistant
- User
error 400 when I run the code
- Assistant
- User
still getting error 400. Can you please descibe for me the sequence of the codes operations
- Assistant
Certainly! Here's the sequence of operations performed by the VBA code provided:
- Unprotect the 'ADMIN RESULTS' worksheet to allow modifications using the specified password.
- Disable event handling to prevent triggering events during the code execution.
- Define variables such as ws (worksheet), adminResults (worksheet), lastRow, i (loop variable), pasteRow, and searchValue (value from cell F2).
- Clear the contents of cells A7:K300 in the 'ADMIN RESULTS' worksheet.
- Set the 'adminResults' worksheet reference to the 'ADMIN RESULTS' sheet.
- User
Check if the cell in column D is not empty and intersects with the ‘listColumn’. does tis mean that the values in column D are checked to see if they exist in the 'listColumn'
- Assistant
Yes, that is correct. The condition "If the cell in column D is not empty and intersects with the 'listColumn'" in the given VBA code means that the code checks if the value in the cell of column D (in the current worksheet being examined) is not empty and if it intersects with the values in the 'listColumn' range from the 'LIST' sheet.
In other words, the code is checking if the value in column D of the current worksheet exists within the values in the 'listColumn' range obtained from the 'LIST' sheet. If both conditions are true, then the code proceeds to copy the specified cell values to the 'ADMIN RESULTS' sheet.
This conditional check ensures that the matching values found in column D of the current worksheet are compared against the values in the 'listColumn' range before copying the corresponding row values to the 'ADMIN RESULTS' sheet.
If you have any further questions or need additional clarification, feel free to ask!
- User
I suspect that it is the prescence of blank cells in both column D and in the 'listColumn' that may be causing the 400 error
- Assistant
- User
can you write a megBox that will display all the values found in this line of code 'Set listColumn = listSheet.Range(listSheet.Cells(24, matchRange.Column), listSheet.Cells(34, matchRange.Column))'
- Assistant
To display all the values found in the 'listColumn' range in a message box, you can iterate through each cell in the range and concatenate the values into a string that will be displayed in the message box. Here's how you can modify the code to achieve this:
- User
- Assistant
The error 400 in Excel VBA can occur due to a variety of reasons, such as referencing a non-existent range, improperly using worksheet functions, or accessing objects that are not available.
In your updated code, the error occurs after the message box because the subsequent part of the code involves interacting with worksheets and ranges. The error may be related to how the 'listColumn' range is being used or how the intersection is checked.
To troubleshoot the error, I recommend the following steps:
-
Check the 'matchRange' value: Before using 'matchRange' to define 'listColumn', verify that 'matchRange' is correctly found and not set to Nothing.
-
Validate the 'listColumn' range: Ensure that the 'listColumn' range is properly defined based on the 'matchRange' column and the rows 24 to 34 of the 'LIST' sheet.
-
- User
The message box reveals the correct 'listColumn' range is identified. What I need to reval are all the rows in sheets with three leeter names that have a value of the 'listColumn' in their column D
- Assistant
- User
Using the style of dispalying results similar to the last code, please write a vba code taht when I select a value in F3, search all the sheets with 3 letter names that contain matches in their column F from row 6 downwards then dispaly the row values as in the previous vba code.
- Assistant
- User
similar to the very last code that you have provided, please write one that dispalys row values where the numeric value in column E is - negative
- Assistant
To display row values where the numeric value in column E is negative for all sheets with three-letter names, you can modify the code as follows:
- User
can I have a formula that like this '=SUM(E7:E300)' but only sums positive nubers found, omitting any negative numbers
- Assistant
If you want to sum only the positive numbers in a range (E7:E300) and omit any negative numbers in Excel, you can use the following array formula:
=SUM(IF(E7:E300>0, E7:E300, 0))This formula uses the IF function within the SUM function to check if each value in the range (E7:E300) is greater than 0. If the value is positive, it includes that value in the sum; otherwise, it excludes it by adding 0.
Remember, since this is an array formula, you need to press Ctrl + Shift + Enter after typing the formula instead of just pressing Enter.
After entering the formula correctly as an array formula, it will calculate the sum of only the positive numbers in the specified range while excluding any negative numbers.
- User
I would like to add to my Worksheet_SelectionChange event, the following condition, If F1, F2 ClearContents F3 Clear contents F4:F5 Calculate
- Assistant
To add the specified conditions to the Worksheet_SelectionChange event in VBA, you can write the following code in the code module of the specific worksheet where you want this behavior:
Private Sub Worksheet_SelectionChange(ByVal Target As Range) If Target.Address = "$F$1" Then Range("F2").ClearContents Range("F3").ClearContents Range("F4:F5").Calculate End If End SubIn the above code:
- The Worksheet_SelectionChange event is triggered when a selection change occurs in the specified worksheet.
- The code checks if the target cell address is "1".
- If the target cell is F1, it clears the contents of cells F2 and F3, and then calculates cells F4:F5.
You can add this code to the code module of the worksheet by right-clicking on the sheet tab, selecting "View Code," and pasting the code into the window that opens. This code will be executed every time a selection change is made in the worksheet, specifically targeting the conditions specified for cell F1.