LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 852
Default Must add 1 to InputBox entry for code to work properly

Code is modified by OP from Claus' original.

Why must I add 1 to the Inputbox entries to return the proper "Week"?

Without the + 1, entries of 2 and 4 return Week1 to Week3.

https://www.dropbox.com/s/lnjqgmpnlc...ader.xlsm?dl=0

Howard

Sub Week_Reader_A_revised()
'/ by Claus @ MS Public (Modified by OP)

Dim fWeek As Long, lWeek As Long, lRow As Long, i As Long
Dim myArr As Variant
Dim f As Range, l As Range, myRng As Range, wkRng As Range

fWeek = Application.InputBox("Enter the STARTING WEEK to search for", "Start Weeknumber", Type:=1) + 1
If fWeek = False Then Exit Sub

lWeek = Application.InputBox("Enter the ENDING WEEK to search for", "Last Weeknumber", Type:=1) + 1
If lWeek = False Then Exit Sub

Sheets("Master").UsedRange.ClearContents

myArr = Array("Bodypump", "Bodystep-step", "Y-Blitz", "Y-Chisel", "Y-Cycle", "Zumba")

Application.ScreenUpdating = False

For i = 0 To UBound(myArr)
Set myRng = Nothing
With Sheets(myArr(i))

Set f = .Range("A2:A100").Find(fWeek, LookIn:=xlValues, lookat:=xlPart)
Set l = .Range("A2:A100").Find(lWeek, LookIn:=xlValues, lookat:=xlPart)
If Not f Is Nothing Then
lRow = Sheets("Master").Cells(Rows.Count, 1).End(xlUp).Row

If lRow = 1 Then
Set wkRng = .Range(fWeek & ":" & lWeek)
Set myRng = Union(.Rows(1), wkRng)
myRng.Copy Sheets("Master").Range("A1")

Else

Set wkRng = .Range(fWeek & ":" & lWeek)
Set myRng = Union(.Rows(1), wkRng)
myRng.Copy Sheets("Master").Cells(lRow + 2, 1)

End If
End If
End With
Next

Sheets("Master").Columns("A:Z").AutoFit
Sheets("Master").Rows("1:200").AutoFit
Application.ScreenUpdating = True
End Sub
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Code to save Word-document do not work properly jkrons Excel Programming 3 May 6th 10 08:44 PM
How to use InputBox for passphrase entry? Joe User[_2_] Excel Programming 4 February 8th 10 03:36 PM
Validate InputBox entry davidm Excel Programming 0 August 31st 05 03:03 AM
Msgbox if Inputbox entry contains character Steph[_3_] Excel Programming 1 June 23rd 05 06:02 PM
Can't get code to work properly. Please Help! sparky3883[_8_] Excel Programming 2 April 15th 04 01:55 PM


All times are GMT +1. The time now is 12:06 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"