Tags down


Creating a loop instead of copy/pasting code over and over

By : Budi Mulyo
Date : September 15 2020, 03:00 PM
will be helpful for those in need You can iterate over the indices, from 1 to however many you have, and concatenate it with input to look up the appropriate property on localStorage:
code :
function loadData(){
  for (let i = 1; i < 10; i++) {
    const parsed = JSON.parse(localStorage.getItem("input" + i));
    $("#planner-input-" + i).val(parsed);
function loadData(){
  const inputs = document.querySelectorAll('.planner-input');
  const parsedArr = JSON.parse(localStorage.getItem("inputs"));
  inputs.forEach((input, i) => {
    input.value = parsedArr[i];

Share : facebook icon twitter icon

Copy and pasting information within a for loop

By : Linda Yunita
Date : March 29 2020, 07:55 AM
Hope this helps I would like to create a function that copies certain excel ranges in worksheets and paste these ranges into a "motherfile". , Adding to mielk's anwser the problem is in the codeline:
code :
Set sourceRange = Sheets(month).range("H7", range("H7").End(xlToRight))
Set sourceRange = Sheets(month).Range("H7", Sheets(month).Range("H7").End(xlToRight))
sourceRange.Copy Destination:=destinationRange
Sub ranges()
Dim month As Variant
Dim months As Variant
months = Array("V01 DEN HAAG", "V02 AMSTERDAM")

For Each month In months
   Dim sourceRange As Excel.Range
   Dim destinationRange As Excel.Range
   With Sheets("DATASET")
      Set destinationRange = .Cells(.Rows.Count, 2).End(xlUp).Offset(1, 0)
   End With
   Set sourceRange = Sheets(month).Range("H7", Sheets(month).Range("H7").End(xlToRight))
   sourceRange.Copy Destination:=destinationRange

Next month
End Sub

Creating a copy of selected worksheets in a workbook and pasting only the values into another and retains formatting of

By : Christine Zenobi
Date : March 29 2020, 07:55 AM
it fixes the issue Save a temporary copy of the source file, then for each sheet run UsedRange.Value = UsedRange.Value to remove the formulas (or just do that on your "report" sheets). Now you can delete the sheets you don't want to keep.
code :
Sub NoFormulas()

    Dim wbTemp As Workbook, tempPath As String, sht As Worksheet, wbReport As Workbook
    Dim ReportPrintOutput As Workbook
    Dim Current As String
    Dim FileName As String

    tempPath = ThisWorkbook.Path & "\" & "temp_" & ThisWorkbook.Name

    ThisWorkbook.SaveCopyAs tempPath
    Set wbTemp = Workbooks.Open(tempPath)
    For Each sht In wbTemp.Worksheets
        sht.UsedRange.Value = sht.UsedRange.Value
    Next sht

    wbTemp.Sheets(Array("Sheet1", "Sheet3")).Copy '<< copy the needed sheets to a new workbook
    Set wbReport = ActiveWorkbook
    wbReport.SaveAs ThisWorkbook.Path & "\Report.xlsx"

    wbTemp.Close False 'close and delete the temporary copy
    Kill tempPath

End Sub

Why isn't my data pasting correctly when I copy and paste it within a For loop?

By : user3303261
Date : March 29 2020, 07:55 AM
I wish this helpful for you I think this is what you want. It takes values in sheet("overview of contacts"), and copies their values to sheet("Sheet1") in column C, descending rows.
code :
Sub Macro3()
    Dim i As Long
    Dim j As Long
    j = 2
    For i = 110 To 116
        Worksheets("Sheet1").Cells(j, 3).Value = Worksheets("Overview of Contracts").Cells(i, 1).Value
        j = j + 1
    Next i
End Sub

For loop while copy and pasting specific columns

By : user3569926
Date : March 29 2020, 07:55 AM
like below fixes the issue The next code has to do what I understood you need. Please check it and confirm this aspect. It is very fast, working only in memory...
code :
Sub PastingNextPage()
  Dim sh As Worksheet, sh1 As Worksheet, arrIn As Variant, arrOut() As Variant
  Dim lastRowIn As Long, lastRowOut As Long, nonEmpt As Long, rngP As Range, nrEl As Long
  Dim i As Long, j As Long, P As Long

  Set sh = Sheets("DATA"): lastRowIn = sh.Range("P" & sh.Rows.count).End(xlUp).Row
  Set sh1 = Sheets("Sheet2"): lastRowOut = sh1.Range("A" & sh1.Rows.count).End(xlUp).Row + 1

  arrIn = sh.Range("G2:Z" & lastRowIn).Value

  nrEl = lastRowIn - Application.WorksheetFunction.CountIf(sh.Range("P2:P" & lastRowIn), "") - 2
    P = 10 'column P:P number in the range starting with G:G column
    ReDim arrOut(nrEl, 3) 'redim the array to keep the collected values
    For i = 1 To lastRowIn - 1
        If arrIn(i, P) <> "" Then
            arrOut(j, 0) = arrIn(i, 1): arrOut(j, 1) = arrIn(i, P): arrOut(j, 2) = arrIn(i, 20)
            j = j + 1
        End If
    Next i

    sh1.Range(sh1.Cells(lastRowOut, "A"), sh1.Cells(lastRowOut + nrEl, "C")).Value = arrOut
End Sub

Loop for copy-pasting values based on names in R

By : iBoughtWinrar
Date : March 29 2020, 07:55 AM
around this issue I have a dataset "datP" that I am trying to add a new variable named "threshold" to. The values I need to add are stored in a test dataframe that looks like this (country codes as rownames and income as the sole variable). I calculated those income values for each country in my main dataset ("DatP") and saved the resulting vector as a "test" dataframe with 32 observations for one variable.
code :
# country dataset (might have other columns as well)
df1 = data.frame(PB020 = c("AT", "BE", "BG", "CH", "BE", "BG", "CY", "CZ"))


#   PB020
# 1    AT
# 2    BE
# 3    BG
# 4    CH
# 5    BE
# 6    BG
# 7    CY
# 8    CZ

# threshold dataset
df2 = read.table(text = "
                 ", header=T)

row.names(df2) = c("AT", "BE", "BG", "CH", "CY", "CZ")


#        thr
# AT 42617.1
# BE 43575.0
# BG 35639.4
# CH 63240.6
# CY 28153.2
# CZ 33948.6

# add row names as a variable
df2$Country = row.names(df2)

# merge them
merge(df1, df2, by.x="PB020", by.y="Country", all.x = T)

#   PB020     thr
# 1    AT 42617.1
# 2    BE 43575.0
# 3    BE 43575.0
# 4    BG 35639.4
# 5    BG 35639.4
# 6    CH 63240.6
# 7    CY 28153.2
# 8    CZ 33948.6
Related Posts Related Posts :
  • How to zero out a time component?
  • In ES6 JavaScript, why is the promise returned by the fulfillment handler of then() not the same as the promise returned
  • Karate DSL - How to read token string from __arg and send this string in json request?
  • how to show variable ${number} instead of NaN
  • how to detect the change of y offset by scrolling without refresh
  • Codility nested algorithm test performance
  • Can a unique Twilio number be used simultaneously by multiple agents?
  • Stop a function running from ANOTHER function in JavaScript
  • Using ag-grid with many rows and Autosave
  • How could this be true??? obj2.__proto__.isPrototypeOf(obj2) //true
  • Regular Expression to get a string between code contianing a dot
  • Javascript nextSibling
  • CSS transform scale fit to window size
  • Nested Array to Query Params for Filters in Searching
  • How to test async code with Jest without passing it as a callback?
  • JavaScript how to sort locale language along with english
  • Two divs scroll simultaneously until one reaches bottom
  • JavaScript: How to check if exactly 4 out of 5 items are the same in an array
  • How to use two or more time picker in jQuery
  • window.open failed on Microsoft Edge
  • Why isn't parameter useable in a function
  • Is the JavaScript ES6 promise exactly the same as Promise/A+?
  • Prevent bootstrap form to submit with "Enter"
  • How to prevent render page from jumping in vuejs?
  • How can capture an image along with logo and text in 3D canvas?
  • Can't read property 'map' of undefined in React app
  • How to check does object is not first or last in array but there are duplicates?
  • Convert Date to DDMMYYYY from any other formats
  • Javascript: getElementsByClassName: how to get only parents
  • Copy a text from a <div> and past in <option> of <select>
  • Passing context to tooltip of ngx bootstrap
  • Route.get() requires a callback function but got a [object Undefined]. What did I do wrong?
  • creating a delete button in javascript to remove shopping list items
  • how to dynamically add value to object in an array of objects in TypeScript?
  • How to upload image Instagram from browser with post request
  • why use callback function in javascript when I can invoke directly a function
  • How to check list is present in other array list in java script ,with out loops
  • How to prevent some scripts on page to not refresh with page reload
  • How to recognise Full House and Two pair in a javascript poker game
  • Chrome DevTools do not show .js files
  • How to link one JS file to two HTML files?
  • How to sort an array to bring out element that are the same?
  • Why does i get following error on npm start
  • Using parser combinator to parse simple math expression
  • jQuery circle menu
  • work with button in form without submit form jsp
  • Web Audio APi Failed to execute 'createMediaElementSource'
  • Why and when does an immediately ignored variable declaration take hold, and overrides a function declaration in subsequ
  • How to generate video thumbnail from input file in javascript?
  • pg-promise using named parameters in an UPDATE SET statement
  • Downloading a large file using Node.js should have less time complexity
  • JavaFX WebView: can't get JS bridge to work in Java11+
  • Loop only iterating once | JS
  • How to return array without square brackets or commas
  • How to solve Cannot update during an existing state issue - react?
  • How to stop execution of a Firebase-triggered Firebase Function?
  • Json on data-attribute
  • How to link routes with controllers in node js?
  • Is it safe to use 'str1 < str2' when any of the input strings possibly represent a numeric value larger than 'Number.
  • Why does my javascript contact-form not work?
  • shadow
    Privacy Policy - Terms - Contact Us © 35dp-dentalpractice.co.uk