Home > Software engineering >  Small white master genuflect is begged help, always can't selected conditions...
Small white master genuflect is begged help, always can't selected conditions...

Time:10-01

There is a table, record the equipment operation log, to select equipment failure and return to normal time,
But after a failure, there will be a specific prompt, will appear again after this prompt or empty lines, it very difficult to make screening,
Because the VBA to beginners, copy copy the east side to the west and a piece of code to run, but always't pick condition records, and modify genuflect is begged, thank you!!!!!



In fact, I want three operations
First, it is within the specified date, choose the F in the column 'Synchronization c... 'character record, save to sheet1, this character indicate that equipment is not normal,
A 'Synchronization c... 'after that, may appear empty data or repeat again' Synchronization c... 'and don't have to ignore it, because when the equipment is not normal,
The second step is to select the equipment is not normal, return to normal, also is saved to the sheet1, at just under the abnormal record
The third step is to the screening of all provinces,

Human hands... Very time consuming, the master can help me to solve, thank you ~

Existing code is as follows:

Sub copy the specified date ()

Dim iStr As String, iDate As the Date,, EndRow2 EndRow1 As Long As Long

IStr=Application. InputBox (" please enter the date ", "date input", "2015-01-14", Type:=2)

If iStr="False" Then Exit Sub

IDate=DateValue (iStr)

A65536 EndRow1=Range (" "). The End (xlUp). Row

For I=2 To EndRow1

If the Range (" C "& amp; I). The Value=https://bbs.csdn.net/topics/iDate Then

If the Range (" F "& amp; I). The Value Like Synchron "* *" Then

EndRow2=Sheets (" Sheet1 "). The Range (" A65536 "). The End (xlUp). Row

Rows (I). Copy Sheets (" Sheet1 "). The Rows (EndRow2 + 1)

If Not Range (" F "& amp; I). The Value Like "* Synchronization c... * "And Range (" F" & amp; I) & lt;> "" Then 'original blank is not empty, there is a space of

Rows (I). Copy Sheets (" Sheet1 "). The Rows (EndRow2 + 1)

END the If

End the If

End the If

Next

End Sub

This code can only find the first condition, the second condition is back to normal condition is I can't find it)

CodePudding user response:

See along while, I don't know what kind of is to normal...

CodePudding user response:

Not acting normal Synchronization

CodePudding user response:

reference 1st floor Topc008 response:
see along while, I don't know what kind of is to normal...


Not a Synchronization or blank is normal

CodePudding user response:

 Sub copy the specified date () 
Dim iStr As String, iDate As the Date, EndRow1 As Long, EndRow2 As Long, As Long I
Dim lStatus As Long '0: not to judge, 1: normal, 2: fault'
Dim bIsChanged As Boolean
Dim sLastProvince As String

IStr=Application. InputBox (" please enter the date ", "date input", "2015-01-14", Type:=2)
If iStr="False" Then Exit Sub
IDate=DateValue (iStr)

'in order to handle multiple provinces, required data must be sorted by (A, D) column, you record A sort of macro copying code here'

A65536 EndRow1=Range (" "). The End (xlUp). Row
EndRow2=Sheets (" Sheet1 "). The Range (" A65536 "). The End (xlUp). Row

For I=2 To EndRow1
If the Range (" C "& amp; I). The Value=https://bbs.csdn.net/topics/iDate Then
If LenB (Trim $(Range (" F "& amp; I))) & lt;> 0 Then 'only non-empty treatment F column'

If the Range (" A "& amp; I) & lt;> SLastProvince Then
A province lStatus=0 'output of the first, if the request must be failure in 1, if also can be back to normal with 0'
SLastProvince=Range (" A "& amp; I)
End the If

If the Range (" F "& amp; I). The Value Like Synchron "* *" Then
BIsChanged=(lStatus & lt;> 2)
LStatus=2
The Else
BIsChanged=(lStatus & lt;> 1)
LStatus=1
End the If

If bIsChanged Then
Rows (I). Copy Sheets (" Sheet1 "). The Rows (EndRow2 + 1)
EndRow2=EndRow2 + 1
End the If

End the If
End the If
Next

End Sub

CodePudding user response:

With the wrong code tag,
 Sub copy the specified date () 
Dim iStr As String, iDate As the Date, EndRow1 As Long, EndRow2 As Long, As Long I
Dim lStatus As Long '0: not to judge, 1: normal, 2: fault'
Dim bIsChanged As Boolean
Dim sLastProvince As String

IStr=Application. InputBox (" please enter the date ", "date input", "2015-01-14", Type:=2)
If iStr="False" Then Exit Sub
IDate=DateValue (iStr)

'in order to handle multiple provinces, required data must be sorted by (A, D) column, you record A sort of macro copying code here'

A65536 EndRow1=Range (" "). The End (xlUp). Row
EndRow2=Sheets (" Sheet1 "). The Range (" A65536 "). The End (xlUp). Row

For I=2 To EndRow1
If the Range (" C "& amp; I). The Value=https://bbs.csdn.net/topics/iDate Then
If LenB (Trim $(Range (" F "& amp; I))) & lt;> 0 Then 'deals only with F columns'

If the Range (" A "& amp; I) & lt;> SLastProvince Then
A province lStatus=0 'output of the first, if the request must be failure in 1, if also can be back to normal with 0'
SLastProvince=Range (" A "& amp; I)
End the If

If the Range (" F "& amp; I). The Value Like Synchron "* *" Then
BIsChanged=(lStatus & lt;> 2)
LStatus=2
The Else
BIsChanged=(lStatus & lt;> 1)
LStatus=1
End the If

If bIsChanged Then
Rows (I). Copy Sheets (" Sheet1 "). The Rows (EndRow2 + 1)
EndRow2=EndRow2 + 1
End the If

End the If
End the If
Next

End Sub
  •  Tags:  
  • VBA
  • Related