Is There A Fast Way To Add Multiple Text boxes With Scrollbars? - excel

Because the cells in my project contain so much data I have had to insert textboxes that have scrollbars to see all the data (they are linked to the cell which sit behind them on the spreadsheet). Is there any fast way to do the same thing on a column of 1000 records or will I have to go through manually and link the textbox to the specific cell? Is there a faster way?
Also If an issue comes in that is a reply to the original issue I need it to use the original ID (I have used auto IDS, which can be seen in the spreadsheet). Any recommendations?
Slowly I am getting better at excel and VBA but I need a hand sometimes ^_^
I have attached the spreadsheet which contains an example of 2 records I made. The final sheet will have 1000 records. (Please download the spreadsheet and open in excel)
LINK To Spreadsheet

A few things:
You should change the cell formatting to "Top Align" the text in the cells. This will cause the cell to show the first line of the long text in the Query cells.
Instead of using the "send email" text in a cell why not add a single button to email the currently selected row. (use insert on the ribbon in the developer tab (you have to change the excel options to show the developer tab).
The code to send an email might be better if it updated a new column with the date it was sent, and in the event that it has already been sent, it could prompt the user to confirm.
if not isempty(cells(r, ColNumberWithSentdate) ) then
if vbno = msgbox ("Are you sure you want to send the email again?", VbYesno) then
Exit sub
end if
end if
All the textboxes you have added are really slowing down the spreadsheet.
why not just have one tall row at the top above the table with the filters. The tall row would show the data from the currently selected row in the table. Your table rows could then probably be less high.
Add a single text box.
Use ALT+click and drag to resize text boxes to fit cell exactly.
Change or view the name of the textbox in the named range area to "TextBoxQuery".
Add code to change the text in the summary row
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
' Say the tall row is in row 2
If Target.Row <= 2 Then
Exit Sub
End If
Dim i As Integer
For i = 1 To 8
Cells(2, i) = Cells(Target.Row, i)
Next i
End Sub
You could even allow the user to edit the text in the tall row and add a button to save the changes they entered:
A. Add an ACTIVEX button in the summary row labelled "SAVE"
(Then you can edit the vba in the sheets module for the button)
B. Add a cell somewhere that records which row is being displayed in the summary row.
C. When the save button is clicked, write code that copies all the values in row to back to the row recorded.
NOTE that if the user deletes a row in the table or sorts the data in the table the row stored will be wrong. So before copying the data, you might like to check to see whether the row has moved. ie check a KEY value (ie ones that never changes) is the saem in both rows.
Private Sub CommandButton1_Click()
Dim i As Integer
For i = 1 To 8
Cells(Cells(1, 1).Value, i) = Cells(2, i)
Next i
End Sub
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
' Say the tall row is in row 2
If Target.Row <= 2 Then
Exit Sub
End If
' Cell A1 is used to store which row is displayed
Cells(1, 1) = Target.Row
Dim i As Integer
For i = 1 To 8
Cells(2, i) = Cells(Target.Row, i)
Next i
End Sub

Related

When I add a row in Excel to copy the previous row's formatting, can I also copy the form control checkboxes?

I have a table with checkboxes in certain columns (see sample table)-- they are linked to their cells and also move/size with the cells. I also added text box "headings" throughout the table so visually when you filter for checked boxes, you see under which heading the checked item is in (I know I could create a separate column for that, but it works if I add text to the cells underneath the heading that I keep checked when filtering).
I want to be able to add rows at the end of each section, or before the next heading, since the formatting changes slightly in each section. However, I also want to add the checkboxes, and my code currently doesn't do that. It's okay if they're not linked to the new cell-- I have another macro I can run to do that.
Here's what my code would look like in the sample table:
Sub Add_Row_Pepperoni()
Rows(7).Insert , xlFormatFromLeftOrAbove
End Sub
Sub Add_Row_Pineapple()
Rows(13).Insert , xlFormatFromLeftOrAbove
End Sub
And I would like to add "Next" to "Call" this code:
Sub Link_CheckBoxes()
Dim chk As CheckBox
Dim lCol As Long
lCol = 0 'number of columns to the right for link
For Each chk In ActiveSheet.CheckBoxes
With chk
.LinkedCell = _
.TopLeftCell.Offset(0, lCol).Address
End With
Next chk
End Sub
My other concern is the row I'm referencing (here rows 7 and 13) will change every time I add a row above it (I'll no longer be referencing the "header" row). Any tips?

How do I fill Excel sheet cells with only the filled text boxes without any empty cells?

I am new to VBA and recently I have been developing a calculator to help do my work. I have created a form with multiple check boxes and text boxes, in my Excel sheet, I have a table that should be filled by the user form. However, I've run into issues, in the user form there is a check box that when checked the user must enter into the text box, I have got exactly eight similar categories (check boxes and text boxes), so all checked boxes and all filled text boxes should be displayed into the cells in the sheet, however they way I done it, is that I use the line:
Range("E5").Value = "Project Manager"
For each of the eight categories, it must fill the cells without leaving any empty cells.
For example, user checks 5 of the 8 boxes and accordingly fills out the text box for each one, if they skipped one of the boxes, it must not do the same when printing them out on the cells.
Private Sub CommandButton1_Click()
Dim PMdays As Integer
If PMcheckBx.Value Then
Range("E5").Value = "Project Manager"
PMdays = PMtextBx.Value
ActiveCell.Offset(0, 1) = PMdays
End If
End Sub
As such, I have attached an image of how I want it to look like and how mine looks like now to help you understand my problem further.
How my sheet looks like
How it should look
You can do something like this:
Private Sub CommandButton1_Click()
Dim PMdays As Integer, c As Range
Set c = ActiveSheet.Range("E5").Value '<< start list here
If PMcheckBx.Value Then
c.Resize(1,2).Value = Array("Project Manager", PMtextBx.Value)
Set c = c.Offset(1, 0) 'move down one row
End If
'next 7 checkboxes
End Sub
Note no ActiveCell/Select/Activate needed.

Move a row of data on top when new data changed in a cell

I have searched everywhere but haven't found solution for my work.
I having a sheet of data which is updated by b PLC to control system in my factory. For example, "workstation1" if is currently working will return a signal as 1, if stop, return 0. So on for workstation2,3,4...
The sheet i'm working on has already displayed the status (0 or 1) of the stations, which like the station name in A column, and the status is in B column.
The problem is, i want when the status of a station changes (1 to 0 or 0 to 1), the whole row of that station move all the way up to the top of the table, so that i can check which station has recently operated. Is this possible to do this?
1 more problem is the data changed is FILLED up automatically by the PLC. I tried some marco which trigger when new data is 'ENTERED' by keyboard, it didn't work.
Thank you in advance and sorry for my bad english.
In your VBA Editor on the left side select ThisWorkbook, then on the top in the left dropdown menu select Workbook, then in the right dropdown select SheetChange.
Include this code:
Private Sub Workbook_SheetChange(ByVal Sh As Object, ByVal Target As Range)
If Target.Column = 2 and Target.Row>2 Then 'after a value changes in B column
Application.EnableEvents = False ' to prevent this change from being seen as another change and causing a loop
Target.EntireRow.Cut
sh.Range("A2").EntireRow.Insert Shift:=xlDown 'A2 because I'm assuming you have a header in your first row
Application.EnableEvents = True 'next sheet changes will cause this to run again
End If
End Sub

VBA adjust copied data

I have two sheets in which I insert data. In sheet1 I have data in column1 and a button.
If I click the button the data will be transfered to sheet2 in row1. Afterwards the user can add captions in column1 and set "x" to the table to sort the captions to the headlines in row1.
The code for that part is not very hard and works perfectly fine.
Private Sub CommandButton1_Click()
Zeile = ActiveSheet.Cells(Rows.Count, 1).End(xlUp).Row
For i = 2 To Zeile
Sheets("2").Cells(1, i) = Sheets("1").Cells(i, 1)
Next i
End Sub
My question is now how I can secure the entered data? If someone is entering in Sheet1 for example an G in between B and C and presses the button a second time it shall not mess up the "x" in Sheet2.
Change in Sheet1
So the column of G has to stay empty but the columns of C,D,E,F shall still have their "x". (In the following picture the inserted Column is highlighted green.
Change in Sheet2 after clicking the button in Sheet1
The user can enter as many rows as he/she wants in sheet1 and it shall be updated by clicking at the button. Do you have an idea how I could realize that?
Thanks!
If I understand you correctly, you could use If statement:
For i = 2 To Zeile
If Sheets("2").Cells(1, i) = "" Then
Sheets("2").Cells(1, i) = Sheets("1").Cells(i, 1)
End If
Next i

How to autopopulate excel column based on dropdown list selection from another column

I have a spreadsheet that has two buttons - To retrieve rows from a sql table using a macro and another one to update data changes back to the table from excel. I have also attached an image here for reference. The table columns are EmpID, EName, Grouping, CCNum,CCName, ResTypeNum, ResName and Status.
Now to update changes, I have drop down lists for CCName and ResName. I would like the ResTypeNum to change automatically whenever the value in ResName column from dropdown list changes. Using Vlookup doesn't seem to work as the formula gets wiped out every time I click on the Retrieve button to refresh data. Also, I have to drag down the formula which I don't want but instead the value in ResTypeNum should automatically update whenever the ResName column is changed. I would appreciate any new ideas to make this work.
Thank you,
Hema
Assumptions:
First value is in A4
ResName column is G
Sheet with data validation list and corresponding code in sheet "ResNameSheet"
In the tables sheet event module you place the following code:
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Column = 7 And Target.Row > 3 Then
If Target.Value2 = "" Then
Target.Offset(0, -1).Value2 = ""
Exit Sub
End If
Dim rngDataValidation As Range
Dim rngRow As Range
Set rngDataValidation = ThisWorkbook.Sheets("ResNameSheet").UsedRange
For Each rngRow In rngDataValidation.Rows
If rngRow.Cells(1, 1).Value2 = Target.Value2 Then
Target.Offset(0, -1).Value2 = rngRow.Cells(1, 2).Value2
End If
Next
End If
End Sub
Explaining how the code works:
Fires on changes to the sheet
checks if changes are in column G (7) and that it occurs below the header row (3)
Checks that the change was not deleting from column G, if it is it clears all values on the corresponding column F
Loops through the Rows collection in the range with ResName list
Checks if values match
If it does it writes the corresponding code to the column to left of Target
Hope this helps.

Resources