Trying to get my code to apply to all sheets on a workbook

ccarrillo54

New Member
Joined
Nov 29, 2018
Messages
2
Hello, I'm trying to get my code to apply to all the sheets, in the workbook I am using. I've tried multiple ways and multiple codes, but nothing I have used worked. So the macro I'm using allows me to check in and out samples, along with the date right beside it. any other code I use to make the code apply to other sheets ends up in error. Please help me, I will greatly appreciate any help or input you can provide. here I the code I am working with.


Option Explicit

Sub Check_In()
Dim Code As String: Code = InputBox("Please scan a barcode", "Scan procedure")
If Code = "" Then MsgBox ("No code scanned"): Exit Sub
Dim NbChIn As Integer: NbChIn = application.CountIf(Range("STORE_RECORDS[CHECKED OUT on its way to analytical lab]"), Code)
Dim NbChOut As Integer: NbChOut = application.CountIf(Range("STORE_RECORDS[SAMPLE RECEIVED from analytical lab]"), Code)

If NbChIn > NbChOut And NbChIn > 0 Then
MsgBox ("This sample is already Checked-out" & Chr(10) & "Please click sample received and retry"): Exit Sub
Else
Cells(Rows.Count, 1).End(xlUp).Offset(1, 0) = Code
Cells(Rows.Count, 1).End(xlUp).Offset(0, 1) = Now
End If
End Sub

Sub Check_Out()
Dim Code As String: Code = InputBox("Please scan a barcode", "Scan procedure")
If Code = "" Then MsgBox ("No code scanned"): Exit Sub
Dim NbChIn As Integer: NbChIn = application.CountIf(Range("STORE_RECORDS[CHECKED OUT on its way to analytical lab]"), Code)
Dim NbChOut As Integer: NbChOut = application.CountIf(Range("STORE_RECORDS[SAMPLE RECEIVED from analytical lab]"), Code)
If NbChIn = NbChOut And NbChIn > 0 Then
MsgBox ("This sample has already been received" & Chr(10) & "Please check it out and retry"): Exit Sub
Else
If Range("STORE_RECORDS[CHECKED OUT on its way to analytical lab]").Find(Code, , , xlWhole, , xlPrevious) Is Nothing Then MsgBox ("No match, ask Carlos !"): Exit Sub
Range("STORE_RECORDS[CHECKED OUT on its way to analytical lab]").Find(Code, , , xlWhole, , xlPrevious).Offset(0, 2) = Code
Range("STORE_RECORDS[CHECKED OUT on its way to analytical lab]").Find(Code, , , xlWhole, , xlPrevious).Offset(0, 3) = Now
End If
End Sub




Here is a preview of what my template looks like, set up in table format.



CHECKED OUT on its way to analytical lab
<colgroup><col width="215" style="width: 161pt;"> <tbody> </tbody>




DATE
<colgroup><col width="215" style="width: 161pt;"> <tbody> </tbody>


SAMPLE RECEIVED from analytical lab
<colgroup><col width="215" style="width: 161pt;"> <tbody> </tbody>




DATE2
<colgroup><col width="215" style="width: 161pt;"> <tbody> </tbody>



AVVUu2IXqqz AF0hYFYdwM8uAAAAAElFTkSuQmCC


CvKt6exFm2CloiTy9CS2iJCC0RoSW0RISWiNASWiJCS0RoCS0RoSUitISWiNASEVpCS0RoiQgtoSUitESE1nOj9U3kucihOhR5PvIfqgvMhgtRBSUAAAAASUVORK5CYII=



<tbody>
</tbody>

<tbody>
</tbody>
4655-003-1

4/17/2019 14:20

4355-007-110

4/23/2019 11:30
4655-003-10
4/17/2019 14:20
4355-007-117

4/23/2019 11:30
4655-003-11

4/17/2019 14:20

4355-007-118
4/23/2019 11:30
4655-003-12

4/17/2019 14:20
4355-007-119

4/23/2019 11:30
4655-003-13

4/17/2019 14:20
4355-007-121
4/23/2019 11:30
4655-003-14
4/17/2019 14:20

4355-007-122
4/23/2019 11:30
4655-003-15
4/17/2019 14:20
4355-007-123
4/23/2019 11:30
4655-003-16
4/17/2019 14:20
4355-007-124
4/23/2019 11:30
4655-003-17
4/17/2019 14:20
4355-007-125
4/23/2019 11:30
4655-003-18
4/17/2019 14:20
4355-007-126
4/23/2019 11:30
4655-003-19
4/17/2019 14:20
4355-007-127
4/23/2019 11:30
4655-003-20
4/17/2019 14:20
4355-007-128
4/23/2019 11:30
4655-003-6
4/17/2019 14:20
4355-007-113
4/23/2019 11:30
4655-003-7
4/17/2019 14:20
4355-007-114
4/23/2019 11:30
4655-003-8
4/17/2019 14:20
4355-007-115
4/23/2019 11:30
4655-003-9
4/17/2019 14:20
4355-007-116
4/23/2019 11:30
4655-003-21
4/18/2019 12:45
4355-007-129
4/23/2019 11:30
4655-003-22
4/18/2019 12:45
4355-007-131
4/23/2019 11:30
4655-003-23
4/18/2019 12:45
4355-007-132
4/23/2019 11:30
4655-003-24
4/18/2019 12:45
4355-007-133
4/23/2019 11:30
4655-003-25
4/18/2019 12:45
4355-007-134
4/23/2019 11:30
4655-003-26
4/18/2019 12:45
4355-007-135
4/23/2019 11:30
4655-003-27
4/18/2019 12:45
4355-007-137


4655-003-28
4/18/2019 12:45
4355-007-138



<tbody>
</tbody>
 

Excel Facts

Quick Sum
Select a range of cells. The total appears in bottom right of Excel screen. Right-click total to add Max, Min, Count, Average.
Just wrap the body of your code in a loop that goes through all sheets, like this:
Code:
    Dim ws As Worksheet
    For Each ws In Worksheets
        ws.Activate
[COLOR=#ff0000]        'YOUR CODE HERE[/COLOR]
    Next ws
 
Upvote 0

Forum statistics

Threads
1,215,945
Messages
6,127,844
Members
449,411
Latest member
adunn_23

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top