Re-sizing Issue

DRX1234

New Member
Joined
Mar 6, 2014
Messages
15
Hi. I have a very handy code that someone on this forum was kind enough to write for me. The code automatically hides columns based on user input. It works perfectly. I type a number (1-10) into a cell, and then depending on the number, a corresponding number of columns hide.

The issue is, when i type anything in any of the last couple of columns (the columns that are off-screen and I need to scroll over to the right to see - columns H-L), after inputting anything into any cell within that column, Excel brings me way far over to the far right, well past any visible columns and I have to scroll back over to input the next cell of data.

I'd like the screen view to stay on whatever column I am working within. Here is the code:

Workbook:
Private Sub Workbook_Open()
Dim C6 As Range
With Worksheets("Submission Form")
Set C6 = .Range("C6")
.Columns("D").Resize(, Columns.Count - 3).Hidden = True
C6.Select
If IsNumeric(C6.Value) And Len(C6.Value) > 0 Then
If C6 > 1 And C6 < 11 Then Columns("D").Resize(, C6 + (C6 > 1)).Hidden = False
End If
End With
End Sub

Worksheet:
Private Sub Worksheet_Change(ByVal Target As Range)
Dim C6 As Variant
C6 = Range("C6").Value
If IsNumeric(C6) And Len(C6) > 0 Then
Columns("D:L").Hidden = True
If C6 > 1 And C6 < 11 Then Columns("D").Resize(, C6 + (C6 > 1)).Hidden = False
End If
End Sub

Any suggestions on how to modify?

Thanks in advance!!
 
What are you tryig to
Take the code
Code:
.Columns("D").Resize(, Columns.Count - 3).Hidden = True
The address of this resized range is $D:$XFD(right most column) because it takes all the columns in the sheet.
So you have to define a new variab
Set r=.range(“A1”).current region
r is data range
dmodify resize code as
Code:
.Columns("D").Resize(, r.Columns.Count - 3).Hidden = True
that is r.columns.count this will hide from D to G (last column of data)
Next resize column you have given c6 +c6>1
What is this c6>1 it is not a number. how can you add it . it will give some wrong address
What are you thinking
Better tell the newsgroup what exactly you want and also POST SMALL EXTRACT OF DATA

IS EVENT CODE WORKBOOKS.OPEN eceessary or you can use a standard macro(s)

introduce message boxes of range addresses, range value etc so that it is easy to debug
 
Upvote 0
Hello. Thank you for your response. I am building a sample submission form. When you open the file, Columns A, B and C are visible. Nothing happens in either column A or B; I need them to remain unhidden. In Column C, cell 6; there is a field that asks for the number of samples to be submitted; a user can input the range of numbers 1 through 10. Below that cell in Column C, reside general questions related to the sample attributes. These same questions are repeated in Columns D-L. If a user enters the number "2" in Cell C6, Column C stays visible and Column D unhides. If they enter a "3", Column C stays visible and Columns D & E unhide. If they enter a "4", Column C stays visible and Columns D, E & F unhide and so on and so forth.

When (depending on the physical screen size of the PC being used) multiple samples are being submitted (>6), you'll need to scroll to the right to input the sample attributes in the appropriate Column, however, the screen view changes and makes the spreadsheet difficult to use. After each cell input, Excel forces you to re-find your place in the spreadsheet. I don't know enough about coding to tell if Event Code Workbooks.Open is necessary. I apologize but my company blocks the HTML maker and I'm not sure how else to post a snapshot or the workbook.
 
Upvote 0
to work on this i have to prepare a sheet with numbers. will it not be helpful to help you if you ca give a small extract of your data ( a few rows including column A B C and few columns D to L so that I can work on it. if you are particular of security of data fill them up with some random data.
 
Upvote 0
OK, try this: They didn't come through but there are comboboxes in cells C21:D27



Excel 2010
ABCDEFGHIJKL
1XXX MICROBIOLOGY: SAMPLE ANALYSIS REQUEST FORM
2
3SAMPLE LOG-IN INFORMATIONDate of Submission:
4Project Number:
5PO: #
6# of Samples Being Submitted:10
7Testing Facility:
8
9SUBMITTER INFORMATIONName:
10Dept:
11Phone #:
12email:
13
14PRODUCT INFORMATIONSample AttributesSample 1Sample 2Sample 3Sample 4Sample 5Sample 6Sample 7Sample 8Sample 9Sample 10
15Product Name
16Formula #
17Sample Code
18Date of Manufacture
19# of containers produced
20Micro-Sensitive Ingredients (Yes/No)
21Process Type
22Sample Type
23Reason for Submission
24Test Demographic
25Distribution Control
26Location Produced
27Preserved
28pH
29Brix
30Juice %
31Co2 Level
32Water Activity
33% Moisture
34Additional info if submitting Raw Ingredients or Type Samples:Manufacturer Name
35Lot Number
36Thermal Process Conditions (if applicable):Pasteurization Time (min)
37Pasteurization Temp (?F)
38Notes FieldIf "Other" was selected above, specify here
40
41SAMPLE INFORMATION (To Be Completed by Microbiology)
42MICRO INFORMATIONTest SelectionSample 1Sample 2Sample 3Sample 4Sample 5Sample 6Sample 7Sample 8Sample 9Sample 10
43APC
44Yeast
45Mold
46Coliform
47E. coli
48Salmonella
49Staphylococcus aureus (coag +)
50Enterobacteriaceae
51OSA
52TPC
53MFmGreen
54Commercial Sterility
55Genus Listeria
56Listeria monocytogenes
Submission Form
 
Upvote 0
Hello Board, any suggestions on how to improve my spreadsheet? I am building a sample submission form and using a code to hide columns (code is in first posting above). When you open the file, Columns A, B and C are visible. Nothing happens in either column A or B; I need them to remain unhidden. In Column C, cell 6; there is a field that asks for the number of samples to be submitted; a user can input the range of numbers 1 through 10. Below that cell in Column C, reside general questions related to the sample attributes. These same questions are repeated in Columns D-L. If a user enters the number "2" in Cell C6, Column C stays visible and Column D unhides. If they enter a "3", Column C stays visible and Columns D & E unhide. If they enter a "4", Column C stays visible and Columns D, E & F unhide and so on and so forth.

When (depending on the physical screen size of the PC being used) multiple samples are being submitted (>6), you'll need to scroll to the right to input the sample attributes into the appropriate Column, however, the screen view changes and makes the spreadsheet difficult to use. After each cell input, Excel forces you to re-find your place in the spreadsheet. To re-find your place, you'll need to press the up or down arrow and Excel will take you back to a view of the column you were working in.

Hopefully I've explained this clearly enough. Snapshot of the file above. Thanks!!
 
Upvote 0
In case anyone is interested, the solve is as follows:

Private Sub worksheet_change(ByVal target As Range)
If Not Intersect(Range("C6"), target) Is Nothing Then
Columns(4).Resize(, Columns.Count - 4).Hidden = True
Columns(3).Resize(, Range("C6") + 0).Hidden = False
End If
End Sub
 
Upvote 0

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