Increment value in range by specific number - excel

For a work project I'm trying to build an excel sheet that lets a user input a number in a dialogue box (or cell) and once a confirmation button is pressed, all numbers in a specific range shall be incremented by the specific value entered by the user. My range is B2:B100 and all cells are either filled with numbers or are empty.
When the user completes his work they'd enter their value in e.g. cell J3 and then press a toggled button underneath. J3 will be cleared and all values in B2:B100 would be incremented by the number entered.
Any help or direction to resources that would cover this would be appreciated. Many thanks.

1) In Excel, Press Alt + F11
2) It will open the VBA editor. copy paste the following code in the editor.
Sub addNumbers()
Dim i As Long
Dim incrementValue As Long
incrementValue = Cells(3, 10).Value
For i = 2 To 100
Cells(i, 2).Value = Cells(i, 2).Value + incrementValue
Next i
End Sub
3)Save this code
4)Go to Developer --> Insert --> Form Controls (Button)
This will open the Assign MAcro window. Select addNumbers. Click on OK.
5) Now you can enter the Desired values in Cell J3 and then click on this button. It will increment Cells B2:B100 by that particular value.

Related

Need VBA code to click button that moves contents from one cell to another

I have a bundle of data on my worksheet that I update every day.
Cell B9 displays the results of a formula that is calculated using this bundle of data. I want to add a button to my Excel worksheet that when clicked will take the value displayed in cell B9 and put it in cell P2 on the same worksheet.
Tomorrow, I'll come in and update the bundle of data, which updates the value displayed in B9, and I'll click the button again which will move the value displayed in B9 to the next available cell in column P.
I'll repeat this process every day to build trended data. My VBA skills are very dim... I can find VBA code to move data from one place to another. I can find VBA code to 'find the next available cell' but I don't know an eloquent way to marry the 2 scripts together to achieve my desired outcome.
Here is your Code:
Sub ExportData()
Dim LastRow As Long
LastRow = ActiveSheet.Range("P1000000").End(xlUp).Row + 1 'first available row
ActiveSheet.Range("P" & LastRow) = ActiveSheet.Range("B9") 'value from P LastRow = Value from Cell B9
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

Excel checkbox change row background color

i create some table, and make a datestamp when i enter data
in column "A" the date is shown in column "E" , so i know when data is entered.
I put checkbox in column "F", but I need help with next:
When checkbox is checked the date must be written in column "G"
The background from "A to D" (but only in this row) must be changed to red color
The data from A, B and C must be copied to another sheet also in A,B and C
I hope someone will help me because i stuck :(
I also attack a screenshot.
Thanks in advance
The procedures will help you get the macro operational, ensure you try the code on a copy of your workbook
Add a command button (ActiveX control) and paste the macro
Note: You need to ensure that you place the Command Button in the worksheet where you have your check boxes.
Step 1:
Copy the “LoopCkBoxesAddDateStampClrCelsCopy()” macro
Sub LoopCkBoxesAddDateStampClrCelsCopy()
Dim lRow As Long
Dim CkBx As OLEObject
'For/Next loop cycles through all checkboxes in worksheet
For Each CkBx In ActiveSheet.OLEObjects
lRow = Sheet2.Cells(Rows.Count, 1).End(xlUp).Row
'If the checkbox is checked then accomplish the lines of code between the If/End If
'The part after the "And" ensures that if a date is in the cell it will not be over written
If CkBx.Object.Value = True And CkBx.TopLeftCell.Offset(, 1).Value = "" Then
'Next line of code puts the date in first cell to left of the checkbox
CkBx.TopLeftCell.Offset(, 1).Value = Format(Date, "mm-dd-yyyy")
'Next line of code colors the first 4 cells in checkboxs' row
CkBx.TopLeftCell.Offset(, -5).Resize(, 4).Interior.Color = vbRed
'Next line of code copies the first 3 cell in the checkbox row to the first empty row on sheet 2
Sheet2.Cells(lRow, 1).Offset(1).Resize(, 3).Value2 = CkBx.TopLeftCell.Offset(, -5).Resize(, 3).Value2
End If
Next CkBx 'loops to the next checkbox
End Sub
Note: If you plan on pasting your cells to a different worksheet, please change both Sheet2s in the code.
Step 2:
On the Developer tab, in the Controls group, click Insert, and then under ActiveX Controls, click the Command Button.
Step 3:
Click the worksheet location where you want the command button to appear.
Step 4:
Right click the button, click View Code. This will launch the Visual Basic Editor.
Step 5:
In the VBE, highlight the Private Sub CommandButton1_Click() and the End Sub, and Paste the macro
Step 6:
Close the Visual Basic Editor, and click Design Mode Button image to ensure design mode is off.
Step 7:
Select the checkboxes in your worksheet and click the button to run the macro

Aligning two columns with partial matches

I am trying to align two columns that have the same partial values, say, up to the 9 first characters.
Some emails in the second column show up without being in the first column.
I would like to know how to match the first column emails to the second column.
I would like to know how to match the first column emails to the second column.
Try,
=match(a2&"*", b:b, 0)
I'm sure you can do this with an Excel formula, but in the meantime, here is a VBA solution. Press ALT + F11 to open the VBA Editor, on the left hand pane locate your Excel file, and under that double-click on "This Workbook". Now paste this code in:
Option Explicit
Private Sub Match()
Dim i As Long
Dim sourceCell As String
'Start at 2 if you have a header on row #1
For i = 2 To ActiveSheet.UsedRange.Rows.Count
'1 is the A column
sourceCell = Cells(i, 1)
'2 is the B column
If Trim(sourceCell) = Left(Trim(Cells(i, 2)), Len(sourceCell)) Then
Cells(i, 3).Value = "Match"
End If
Next i
End Sub
Now make sure that you have the correct Excel sheet open and again from the VBA editor click on Run -> Run Sub/User form.
CAUTION - It will report results and overwrite any data in your "C" column. If you need to change this, just change the Cells(i, 3) value from 3 to another column.

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

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

Resources