value of cell is not recognized as equal to listbox items even though it is - excel

My code doesn't recognize cell values as equal to listbox items even though it is. Everything works perfectly until it begins the loop, where it then doesn't consider SelItem the same value as the cell value. I ran the loop seperately without it being part of the Userform sub and here it works fine.
I looked up in Locals window and the SelItem is a Variant/String variable and I guess it should be compatible with a cell value?
Please see code below.
Sub CommandButton3_Click()
Dim SelectedItems As String, LastRow As Long
Dim selItem As Variant, selItems As Variant
For i = 0 To CountryList.ListCount - 1
If CountryList.Selected(i) = True Then
SelectedItems = SelectedItems & CountryList.List(i) & vbNewLine
End If
Next i
If SelectedItems = "" Then
MsgBox "Please select minimum one country"
Else
CountrySelection.Hide
'Create New Sheet
Set WS = Sheets.Add(after:=Sheets(Worksheets.Count))
WS.Name = "Country Selection"
'If Sheet is VeryHidden
Dim WasHidden
Application.ScreenUpdating = False
If Sheets("Country Split").Visible = xlSheetVeryHidden Then
Sheets("Country Split").Visible = xlSheetVisible
WasHidden = True
End If
Sheets("Country Split").Select
Cells.Select
Selection.Copy
Sheets("Country Selection").Select
Range("A1").Select
ActiveSheet.Paste
'Format As Table
Set StartCell = Range("D10")
StartCell.CurrentRegion.Select
ActiveSheet.ListObjects.Add(xlSrcRange, , , xlYes).Name = _
"Country_Selection"
producttable = ActiveSheet.ListObjects("Country_Selection")
If WasHidden Then Sheets("Country Split").Visible = xlSheetVeryHidden
LastRow = ActiveSheet.Range("F1").SpecialCells(xlCellTypeLastCell).Row
SelectedItems = Left(SelectedItems, Len(SelectedItems) - 1)
selItems = Split(SelectedItems, vbNewLine)
This is where it read If Range("F" & i).Value = selItem as not the same thing even though it is.
For Each selItem In selItems
For i = 11 To LastRow
If Range("F" & i).Value = selItem Then Rows(i).Hidden = True
Next i
Next
End If
For i = 11 To LastRow
If Rows(i).Hidden = True Then Rows(i).EntireRow.Delete
Next
Unload CountrySelection
End Sub

Related

Find a specific text and cut all the lines below it and paste to another sheet

I am trying to find the word "BREAK" and cut the lines below it until it reaches another word "BREAK" and transfer it to another Sheet.
I need to separate it to 5 sheets since I have 5 word of "BREAK" in the file.
Sub Fails()
Dim mFind As Range
Set mFind = Columns("A").Find("BREAK")
If mFind Is Nothing Then
MsgBox "There is no cell found with the text 'BREAK'" _
& " in column A of the active sheet."
Exit Sub
End If
firstaddress = mFind.Address
Do
If IsDate(mFind.Offset(1, 0)) = True Then
Range(mFind, Cells(mFind.Row + 2, "A")).EntireRow.Cut
Sheets("Sheet2").Select
Range("A" & Rows.Count).End(xlUp).Offset(1, 0).Select
ActiveSheet.Paste
ElseIf WorksheetFunction.IsNumber(mFind.Offset(1, 0)) = True Then
Range(mFind, Cells(mFind.Row + 3, "A")).EntireRow.Cut
Sheets("Sheet2").Select
Range("A" & Rows.Count).End(xlUp).Offset(1, 0).Select
ActiveSheet.Paste
End If
Sheets("Sheet1").Select
Set mFind = Columns("A").FindNext(mFind)
If mFind Is Nothing Then Exit Sub
Loop While mFind.Address <> firstaddress
End Sub
Nothing is happening with the code above. Any help would be greatly appreciated.
Thank you and have a good day everyone.
Give this code a try, your If statement was false
Sub Fails()
Dim mFind As Range
Dim Compteur As Integer
Dim IdSheet As Integer
Dim ErrorBool As Boolean
Set mFind = Columns("A").Find("Break")
Set mfind2 = Columns("A").Find("Break")
If mFind Is Nothing Then
MsgBox "There is no cell found with the text 'Break'" _
& " in column A of the active sheet."
Exit Sub
End If
firstaddress = mFind.Address
IdSheet = 1
Compteur = 0
Do
Set mfind2 = Columns("A").FindNext(mFind)
If mfind2 Is Nothing Then
Compteur = Sheet1.Range("A1048576").End(xlUp).Row
'Exit Sub
Else:
If mFind.Row < mfind2.Row Then
Compteur = mfind2.Row
End If
If mFind.Row > mfind2.Row Then
ErrorBool = True
End If
If ErrorBool = True Then
Range(mFind, Cells(mFind.Row + 1, "A")).EntireRow.Cut
End If
End If
Range("A" & mFind.Row + 1 & ":A" & Compteur - 1).EntireRow.Cut
If mFind Is Nothing Then
Else: IdSheet = IdSheet + 1
End If
Sheets("Sheet" & IdSheet & "").Select
Range("A" & Rows.Count).End(xlUp).Offset(1, 0).Select
ActiveSheet.Paste
Sheets("Sheet1").Select
Range(mFind, Cells(mFind.Row, "A")).EntireRow.Delete
Set mFind = Columns("A").Find("Break")
Set mfind2 = Columns("A").Find("Break")
If mFind Is Nothing Then Exit Sub
Set mFind = Columns("A").FindNext(mFind)
Loop While mFind.Address <> firstaddress
End Sub
Note : You must create Sheet1, Sheet2, Sheet3, Sheet4 ,Sheet5 and so on before run macro.

Delete Blank Lines

I need to have this code look from the bottom up and once it reaches a cell in Column G that is populated it stops deleting lines. Can some one help me out. There will be blanks in column G but, I just need it to look from the bottom up to the last populated cell in column G and delete everything below that.
Routine to Delete Blank Lines to the Datasheet, Uncertainty and Repeatability Sheets
Public Sub DeleteBlankLines()
' Declaring the variables
Dim WS As Worksheet
Dim UncWs As Worksheet, RepWs As Worksheet, ImpWs As Worksheet
Dim StopAtData As Boolean
Dim UserAnswer As Variant
Dim rngDelete As Range, UncDelete As Range, RepDelete As Range, ImpDelete As Range
Dim RowDeleteCount As Integer
'Set Worksheets
Set UncWs = ThisWorkbook.Sheets("Uncertainty")
Set RepWs = ThisWorkbook.Sheets("Repeatability")
Set WS = ThisWorkbook.Sheets("Datasheet")
Set ImpWs = ThisWorkbook.Sheets("Import Map")
'Set Delete Variables to Nothing
Set rngDelete = Nothing
Set UncDelete = Nothing
Set RepDelete = Nothing
Set ImpDelete = Nothing
RowDeleteCount = 0
'Determine which cells to delete
UserAnswer = MsgBox("Do you want to delete empty rows " & _
"outside of your data?" & vbNewLine, vbYesNoCancel)
If UserAnswer = vbYes Then
StopAtData = True
'Not needed Turn off at Call in Form
'Application.Calculation = xlCalculationManual
'Application.ScreenUpdating = False
'Application.EnableEvents = False
' Set Range
DS_LastRow = WS.Range("A" & WS.Rows.Count).End(xlUp).Row
For CurrentRow = DS_StartRow To DS_LastRow Step 1
' Delete blank rows by checking the value of cell in column G (Nominal Value)
With WS.Range("G" & CurrentRow & ":O" & CurrentRow)
If WorksheetFunction.CountBlank(.Cells) >= 9 Then
If rngDelete Is Nothing Then
Set rngDelete = WS.Rows(CurrentRow)
Set UncDelete = UncWs.Rows(CurrentRow)
Set RepDelete = RepWs.Rows(CurrentRow)
Set ImpDelete = ImpWs.Rows(CurrentRow)
RowDeleteCount = 1
Else
Set rngDelete = Union(rngDelete, WS.Rows(CurrentRow))
Set UncDelete = Union(UncDelete, UncWs.Rows(CurrentRow))
Set RepDelete = Union(RepDelete, RepWs.Rows(CurrentRow))
Set ImpDelete = Union(ImpDelete, ImpWs.Rows(CurrentRow))
RowDeleteCount = RowDeleteCount + 1
End If
End If
End With
Next CurrentRow
Else
Exit Sub
End If
'Refresh UsedRange (if necessary)
If RowDeleteCount > 0 Then
UserAnswer = MsgBox("This will Delete " & RowDeleteCount & " rows, Do you want to delete empty rows?" & vbNewLine, vbYesNoCancel)
If UserAnswer = vbYes Then
' Delete blank rows
If Not rngDelete Is Nothing Then
UncWs.Unprotect ("$1mco")
RepWs.Unprotect ("$1mco")
rngDelete.EntireRow.Delete Shift:=xlUp
UncDelete.EntireRow.Delete Shift:=xlUp
RepDelete.EntireRow.Delete Shift:=xlUp
ImpDelete.EntireRow.Delete Shift:=xlUp
UncWs.Protect "$1mco", , , , , True, True
RepWs.Protect ("$1mco")
End If
Else
MsgBox "No Rows will be Deleted.", vbInformation, "No Rows Deleted"
End If
Else
MsgBox "No blank rows were found!", vbInformation, "No Blanks Found"
End If
' Set New Last Row Moved to Event
DS_LastRow = WS.Range("A" & WS.Rows.Count).End(xlUp).Row
'Update Line Count on Datasheet
WS.Range("A9").Value = DS_LastRow - DS_StartRow + 1
'Not needed Turn on at Call in Form
'Application.Calculation = xlCalculationAutomatic
'Application.ScreenUpdating = True
'Application.EnableEvents = True
End Sub
Delete Below Last Row
Instead of Delete you can use Clear, or if you want to preserve the formatting below the last row, you can use ClearContents.
The Code
Option Explicit
Sub DelRows()
Const cSheet As Variant = "Sheet1" ' Worksheet Name/Index
Const cColumn As Variant = "G" ' Cirteria Column Letter/Number
Dim lastR As Long ' Last Row
With ThisWorkbook.Worksheets(cSheet)
lastR = .Cells(.Rows.Count, cColumn).End(xlUp).Row
.Range(.Cells(lastR + 1, 1), .Cells(.Rows.Count, 1)).EntireRow.Delete
End With
End Sub

macro causing excel sheet to show segregated lines? How to get rid?

I am running this macro:
Sub Check()
ActiveSheet.EnableCalculation = False
Application.ScreenUpdating = False
Application.DisplayStatusBar = False
Application.EnableEvents = False
ActiveSheet.DisplayPageBreaks = False
If Sheets(1).Range("A1").Value = "Enter Data" Then
Sheets(2).Activate
Else
If Sheets(1).Range("H10").Value <> "" And Sheets(1).Range("I10").Value <> "" And Sheets(1).Range("J10").Value <> "" Then
Dim lastRow As Long
Dim sht1 As Worksheet
Dim sht2 As Worksheet
Set sht1 = Sheets(2)
If sht1.Range("A1").Value <> "" Then
'insert column b formula
lastRow = sht1.Range("A" & Rows.Count).End(xlUp).Row
sht1.Range("B2").Formula = "=MID(A2, 1, 12)"
sht1.Range("B2").AutoFill Destination:=sht1.Range("B2:B" & lastRow)
'insert column c formula
sht1.Range("C2").Formula = "=--LEFT(B2,4)"
sht1.Range("C2").AutoFill Destination:=sht1.Range("C2:C" & lastRow)
'insert column d formula
sht1.Range("D2").Formula = "=--RIGHT(MID(A2, 14, 7),LEN(MID(A2, 14, 7))-FIND(LEFT(SUBSTITUTE(MID(A2, 14, 7)&"" "",""0"",""""),1),MID(A2, 14, 7)&"" "")+1)"
sht1.Range("D2").AutoFill Destination:=sht1.Range("D2:D" & lastRow)
'insert column E formula
sht1.Range("E2").Formula = "=DATE(""20""&MID(B2,9,2),MID(B2,7,2),MID(B2,5,2))"
sht1.Range("E2").AutoFill Destination:=sht1.Range("E2:E" & lastRow)
'insert column F formula
sht1.Range("F2").Formula = "=IF(E2<>"""",WEEKNUM(E2,21),"""")"
sht1.Range("F2").AutoFill Destination:=sht1.Range("F2:F" & lastRow)
'insert column G formula
sht1.Range("G2").Formula = "=SUBSTITUTE(TRIM(MID(A2, FIND(""-"", A2, FIND(""-"", A2)+9)+9,256)),"" "","" / "")"
sht1.Range("G2").AutoFill Destination:=sht1.Range("G2:G" & lastRow)
Else
MsgBox "Please First Copy and Paste Estimated Receivings."
End If
Set sht2 = Sheets(1)
With sht2
If Range("H10").Value <> "" Then
lastRow = .Cells(.Rows.Count, 10).End(xlUp).Row
.Range("K10").FormulaArray = "=IFERROR(INDEX(Data!$G:$G,MATCH(1,(Home!$H10=Data!$C:$C)*(Home!$I10=Data!$D:$D)*(IF(Home!$J10<55,Home!$J10,WEEKNUM(Home!$J10,21))=Data!$F:$F),0)),"""")"
If lastRow <> 10 Then
.Range("K10").AutoFill ActiveSheet.Range("K10:K" & lastRow)
End If
.Range("M10").FormulaArray = "=IFERROR(INDEX(Data!$B:$B,MATCH(1,(Home!$H10=Data!$C:$C)*(Home!$I10=Data!$D:$D)*(IF(Home!$J10<55,Home!$J10,WEEKNUM(Home!$J10,21))=Data!$F:$F),0)),""No Po Found"")"
If lastRow <> 10 Then
.Range("M10").AutoFill ActiveSheet.Range("M10:M" & lastRow)
End If
.Range("L10").FormulaArray = "=IFERROR(INDEX(Data!$F:$F,MATCH(1,(Home!$H10=Data!$C:$C)*(Home!$I10=Data!$D:$D)*(IF(Home!$J10<55,Home!$J10,WEEKNUM(Home!$J10,21))=Data!$F:$F),0)),"""")"
If lastRow <> 10 Then
.Range("L10").AutoFill ActiveSheet.Range("L10:L" & lastRow)
End If
Else
MsgBox "Please enter some data."
End If
End With
Else
MsgBox "At Least One Order Must Be Checked."
End If
End If
Application.ScreenUpdating = True
Application.DisplayStatusBar = True
Application.EnableEvents = True
ActiveSheet.DisplayPageBreaks = True
ActiveSheet.EnableCalculation = True
End Sub
For some reason, when the code has finished running, my excel sheet displays three segregated lines like this:
Why is this, and how can i remove them? I appreciate any help. Thanks
I think you should remove
ActiveSheet.DisplayPageBreaks = True

Use stored value to call or create & call sheet

I have a workbook that creates other workbooks and shifts data to them based on the value in column one. Afterwords I need the workbook to store the data it has just copied in a sheet of the same name as the stored variable (in the next empty row), or create the tab if it does not exist.
However i'm having an issue pasting into the tab with the name of the variable, and no idea how to create a new sheet if the variable does not already exist as a sheet.
It's the With Worksheets(SupID).Range("A" & LastRow(SupID) + 1).Paste i'm having trouble with.
Current code below. Thanks!
Private Sub CopyItOver()
Dim myVal As String
Dim SupID As String
'Store Supplier ID
SupID = Trim(Sheets("Raw Data").Range("A2").Value)
'Create workbook
Set newbook = Workbooks.Add
'Copy Records
Set myRng = Workbooks("Book1.xlsm").Worksheets("Raw Data").Range("B2:X7")
myRng.Copy
newbook.Worksheets("Sheet1").Range("A2").PasteSpecial (xlPasteValues)
'Create Header
newbook.Worksheets("Sheet1").Range("A1").Value = "ZHF"
newbook.Worksheets("Sheet1").Range("B1").Value = "CTO"
newbook.Worksheets("Sheet1").Range("C1").Value = "RET"
newbook.Worksheets("Sheet1").Range("D1").Value = SupID
newbook.Worksheets("Sheet1").Range("E1").Value = "RET"
newbook.Worksheets("Sheet1").Range("F1").Value = "RET"
newbook.Worksheets("Sheet1").Range("G1").Value = "6"
newbook.Worksheets("Sheet1").Range("H1").Value = "PROD"
newbook.Worksheets("Sheet1").Range("J1").Value = newbook.Worksheets("Sheet1").Range("B1").Value _
& newbook.Worksheets("Sheet1").Range("D1").Value & "TEMPNUMBER"
newbook.Worksheets("Sheet1").Range("I1").Value = newbook.Worksheets("Sheet1").Range("J1").Value _
& newbook.Worksheets("Sheet1").Range("C1").Value & ".CSV"
newbook.Worksheets("Sheet1").Range("K1") = Format(Date, "ddmmyyyy")
newbook.Worksheets("Sheet1").Range("L1").Value = "Unknown"
newbook.Worksheets("Sheet1").Range("M1").Value = "1"
LastRow = newbook.Worksheets("Sheet1").Cells(Rows.Count, "A").End(xlUp).Row
'Create Footer
newbook.Worksheets("Sheet1").Range("A" & LastRow + 1).Value = "ZFV"
newbook.Worksheets("Sheet1").Range("B" & LastRow + 1).Value = "BATCH" & "TEMPNUMBER"
newbook.Worksheets("Sheet1").Range("C" & LastRow + 1).Value = WorksheetFunction.CountIf(Sheets("Sheet1").Range("A1:A1000"), "RET")
'Name Sheet
myVal = newbook.Worksheets("Sheet1").Range("J1").Value & "RET"
newbook.Worksheets("Sheet1").Name = myVal
'Copy to relevant matching sheet
With Worksheets(SupID).Range("A" & LastRow(SupID) + 1).Paste
End With
'Save Workbook
NewBook.SaveAs Filename:=NewBook.Worksheets("Sheet1").Range("I1").Value
End Sub
Function DLastRow(sh As Worksheet)
On Error Resume Next
LastRow = sh.Cells.Find(What:="*", _
After:=sh.Range("A1"), _
Lookat:=xlPart, _
LookIn:=xlValues, _
SearchOrder:=xlByRows, _
SearchDirection:=xlPrevious, _
MatchCase:=False).Row
On Error GoTo 0
End Function
The error's occurring because Worksheets(SupID).Range("A" & LastRow(SupID) + 1).Paste is trying to find that worksheet on your active book, ie the new book. You'd need either to Activate your raw data workbook or change the line to ThisWorkbook.Worksheets(SupID).Range("A" & LastRow(SupID) + 1).Paste.
However, it's not great to use (either explicitly or implicitly) Activate, Select or other keystroke style commands in VBA. Given that you're only copying values (and not the worksheet formats) then, you'd probably be better served reading the data into an array of variants and manipulating those. I've adjusted your code to demonstrate this.
There are some other coding aspects that might not be as robust as they could be. I won't list them all but a comparison of this code with yours will help you see them.
Private Sub CopyItOver()
Dim newBook As Workbook
Dim supSheet As Worksheet
Dim v As Variant
Dim supID As String
Dim namePrefix As String
Dim footerCount As Integer
Dim i As Integer
'Store Supplier ID
supID = Trim(ThisWorkbook.Worksheets("Raw Data").Range("A2").value)
namePrefix = "CTO" & supID & "TEMPNUMBER"
'Create workbook
Set newBook = Workbooks.Add
'Copy Records
v = rawDataSheet.Range("B2:X7").value
For i = 1 To UBound(v, 1)
If v(i, 1) = "RET" Then footerCount = footerCount + 1
Next
'Write new sheet
With newBook.Worksheets(1)
'Values
.Range("A2").Resize(UBound(v, 1), UBound(v, 2)).value = v
'Header
.Range("A1").Resize(, 13) = Array( _
"ZHF", "CTO", "RET", supID, "RET", "RET", "6", "PROD", _
namePrefix & "RET.CSV", namePrefix, _
Format(Date, "ddmmyyyy"), "Unknown", "1")
'Footer
.Cells(.Rows.Count, "A").End(xlUp).Offset(1).Resize(, 3).value = Array( _
"ZFV", "BATCH TEMPNUMBER", footerCount)
'Name
.Name = namePrefix & "RET"
'Save
.SaveAs Filename:=namePrefix & "RET.CSV"
End With
'Copy to relevant matching sheet
On Error Resume Next
Set supSheet = ThisWorkbook.Worksheets(supID)
On Error Goto 0
If newSheet Is Nothing Then
With ThisWorkbook.Worksheets
Set supSheet = .Add(After:=.Item(.Count))
End With
supSheet.Name = supID
End If
With supSheet
.Cells(.Rows.Count, "A").End(xlUp).Offset(1).Resize(UBound(v, 1), UBound(v, 2)).value = v
End With
End Sub
A few things that aren't quite right:
Add Option Explicit at the top of the module and declare your variables.
LastRow will be a Long data type, but you're trying to use it like an array in With Worksheets(SupID).Range("A" & LastRow(SupID) + 1).Paste. Just use LastRow+1.
With Worksheets(SupID).Range("A" & LastRow(SupID) + 1).Paste
End With should probably be Worksheets(SupID).Range("A" & LastRow + 1).Paste, but it will paste myRng - can't see anything else you've copied.
At the start of the code you reference Workbooks("Book1.xlsm"). If this is the workbook that the code is in I'd change it to ThisWorkbook.
SupID looks at Raw Data on whichever workbook is active at the time (you'd don't specify the workbook when initialising that variable).
This function will return TRUE/FALSE if a named worksheet exists:
Public Function WorkSheetExists(SheetName As String) As Boolean
Dim wrkSht As Worksheet
On Error Resume Next
Set wrkSht = ThisWorkbook.Worksheets(SheetName)
WorkSheetExists = (Err.Number = 0)
Set wrkSht = Nothing
On Error GoTo 0
End Function
Hope that points you in the right direction :)
Edit:
Just noticed to....
Rather than write:
newbook.Worksheets("Sheet1").Range("A1").Value = "ZHF"
newbook.Worksheets("Sheet1").Range("B1").Value = "CTO"
newbook.Worksheets("Sheet1").Range("C1").Value = "RET"
newbook.Worksheets("Sheet1").Range("D1").Value = SupID
newbook.Worksheets("Sheet1").Range("E1").Value = "RET"
newbook.Worksheets("Sheet1").Range("F1").Value = "RET"
newbook.Worksheets("Sheet1").Range("G1").Value = "6"
newbook.Worksheets("Sheet1").Range("H1").Value = "PROD"
You can just use:
newbook.Worksheets("Sheet1").Range("A1:H1") = Array("ZHF", "CTO", "RET", "SupID", "RET", "RET", "6", "Prod")
I managed to resolve my issue using help from Here, to which I adapted to the code below and ran in a separate module, which allows for the use of a previously unspecified sheet name, that is later derived from a cell value. If the sheet does not exist, it is created matching the name to the stored value and the data pasted into it. Thanks for the support!
Sub TEST()
Dim i As Integer, blnFound As Boolean
blnFound = False
SupID = Trim(Sheets("Raw Data").Range("A2").Value)
Set myRng = Workbooks("Book1.xlsm").Worksheets("Raw Data").Range("B2:X7")
myRng.Copy
With ThisWorkbook
For i = 1 To .Sheets.Count
If .Sheets(i).Name = SupID Then
blnFound = True
.Sheets(i).Activate
ActiveSheet.Paste Destination:=Range("A" & LastRow + 1)
Exit For
End If
Next i
If blnFound = False Then
.Sheets.Add
With ActiveSheet
.Name = SupID
ActiveSheet.Paste Destination:=Range("A" & LastRow + 1)
End With
End If
End With
End Sub

Setting up if cell is blank don't continue... and show a message

This code works perfectly. I only have one question, I want to make it so that if there is nothing in cell Q23 that it will not put anything into NCMR Data, and say something... the code is below of what I have, and below it is what I think I need to do to a specific section to work, can someone review and make sure I am on the right path?
Option Explicit
Sub NCMR()
Dim i As Integer
With Application
.ScreenUpdating = False
End With
'Internal NCMR
Dim wsInt As Worksheet
Dim wsNDA As Worksheet
'Copy Ranges
Dim c As Variant
'Paste Ranges
Dim P As Range
'Setting Sheet
Set wsInt = Sheets("NCMR Input")
Set wsNDA = Sheets("NCMR Data")
Set P = wsInt.Range("B61:V61")
With wsInt
c = Array(.Range("B11"), .Range("B14"), .Range("B17"), .Range("B20"), .Range("Q23"), .Range("B23") _
, .Range("Q11"), .Range("Q14"), .Range("Q17"), .Range("Q20"), .Range("R26"), .Range("V23") _
, .Range("V25"), .Range("V27"), .Range("B32"), .Range("B40"), .Range("B46"), .Range("B52") _
, .Range("D58"), .Range("L58"), .Range("V58"))
End With
For i = LBound(c) To UBound(c)
P(i + 1).Value = c(i).Value
Next
With wsNDA
Dim LastRow As Long
LastRow = .Range("A" & Rows.Count).End(xlUp).Row + 1
wsInt.Rows("61").Copy
With .Rows(LastRow)
.PasteSpecial Paste:=xlPasteFormats
.PasteSpecial Paste:=xlPasteValues
.Interior.Pattern = xlNone
End With
With .Range("A" & LastRow)
If LastRow = 3 Then
.Value = 1
Else
.Value = Val(wsNDA.Range("A" & LastRow - 1).Value) + 1
End If
.NumberFormat = "0#######"
End With
End With
With Application
.Range("A61:V61").ClearContents
.ScreenUpdating = True
End With
End Sub
What I want to do I think:
With wsInt
Dim f As Range
Set f = .Cell("Q23")
If IsEmpty(f) Then
MsgBox "The data can't entered, you have not entered any data into the Sales Order field."
Else
c = Array(.Range("B11"), .Range("B14"), .Range("B17"), .Range("B20"), .Range("Q23"), .Range("B23") _
, .Range("Q11"), .Range("Q14"), .Range("Q17"), .Range("Q20"), .Range("R26"), .Range("V23") _
, .Range("V25"), .Range("V27"), .Range("B32"), .Range("B40"), .Range("B46"), .Range("B52") _
, .Range("D58"), .Range("L58"), .Range("V58"))
End If
End With
Maybe as simple as:
With wsInt
If Len(.Range("Q23")) = 0 Then
MsgBox "The data can't be entered, you have not entered any data into the Sales Order field."
Exit Sub
End If
End With 'added this line for clarity

Resources